Basically I am trying to convert each letter of an array to a number, that is also an array, but trying to do it with a for and ascii, it is creating an infinite cycle, can you help?
I created a for with variable "I" until its letters array length, and tried to transform its characters array type char into an array int number, but it is not working properly.
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
char teste();
int main(int argc, char *argv[]) {
// inicializing variables
int i = 0, i2 = 0;
char b[]={};
int numero[] = {};
// reads its array "b"
scanf("%s",b);
// and writes it
printf("%s\n",b);
// writes the number which each letter of the array corresponds (What I wanted)
printf("%i", string_tamanho( b));
for(i = 1; i<= string_tamanho(b); i++){
numero[i] = b[i] - 96;
printf("%i\t", numero[i]);
}
}
int string_tamanho(char b[]) {
// initializing conta variable (stores the length of the string)
int conta;
// incrementing the count till the end of the string
for (conta = 0; b[conta] != '\0'; ++conta);
// returning the character count of the string
return conta;
}