Perhaps something like:
You need to remove the trailing new line character before you use either fgets() or the scanf().Code:#include <stdio.h> #include <string.h> int main() { char apple[100]; char goat[100]; scanf("%99s", goat); // Get rid of any characters remaining in the input buffer. while ( getchar() != '\n' ); if(strcmp(goat, "something") == 0) { scanf("%99[^\n]", apple); // Or use fgets(). // fgets(apple, 100, stdin); } printf("%s\n", apple); return 0; }
Jim