I'm really new to programming and just wanted to ask a quick question. So I made this program that reads off whatever the user inputs, then output the exact same thing until the user presses enter without any input.
int main(void) {
char s1[30];
while (s1[0] != NULL) {
gets(s1);
printf("%s\n", s1);
}
system("PAUSE");
return 0;
}
Then I realized that when I press enter to end the program, the program creates an extra blank line before the program terminates.
So I changed my code as it is below
int main(void) {
char s1[30];
while (1) {
gets(s1);
if (s1[0] == NULL)
break;
printf("%s\n", s1);
}
system("pause");
return 0;
}
And now the program terminates without creating an extra blank line. But I really can't seem to figure out the factors that made the difference between two codes.
Any help would be appreciated. Thanks!