I'm doing an exercise where I have to do the given word with input exit in reverse order.
I start by counting the number of letters that have the word entered (commented in the code). After having counted the number of letters in the word I pass this value (number of letters) to another loop that will show the word in reverse order. For example: if the word is "test" I will have l = 5 , passing the value of L to I, the print order in loop would be subscript 5 of the array name
, then the 4, then 3 ... but that is not working.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, l = 0;
char name[50];
printf("Tell me a word: \n");
scanf("%s", name);
for( i = 0; name[i] != '#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, l = 0;
char name[50];
printf("Tell me a word: \n");
scanf("%s", name);
for( i = 0; name[i] != '%pre%'; i++){ /* até aqui o código irá simplesmente
contar o number de letras na palavra digitada*/
l++;
}
if(name[i] == '%pre%'){
printf("The number of letters is %d\n", l); /* o programa só funciona até
aqui*/
}
printf("The word is the reverse order is\n");
for( i = l; i != 0; i--){
printf("%d", name[i]);
}
return 0;
}
'; i++){ /* até aqui o código irá simplesmente
contar o number de letras na palavra digitada*/
l++;
}
if(name[i] == '%pre%'){
printf("The number of letters is %d\n", l); /* o programa só funciona até
aqui*/
}
printf("The word is the reverse order is\n");
for( i = l; i != 0; i--){
printf("%d", name[i]);
}
return 0;
}