Im am doing a several exercises to manipulate string and all of them i need to give option for the user repeat the program. But the program only reads my first fgets.
Here goes one example
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
int i;
char text[150], ch;
do {
printf("Enter a text with up to 150 characters");
fgets(texto, sizeof(texto), stdin);
printf("\n=== INVERTED TEXT ===\n");
for(i=strlen(text); i >= 0; i--){
putchar(texto[i]);
}
printf("\n\n Do you wish to repeat the program ?(Y/N).: ");
fflush(stdin);
scanf("%c", &ch);
} while(toupper(ch) == 'Y');
return 0;
}
In the first loop the programs executes well, but then its doesn't let me input a new value for variable text. Is there an easy way to solve this?