Code:
#include <stdio.h>
int main()
{
int line;
char userInput[6][160];
for (line = 0 ; line < 6; line++)
fgets(userInput[line], 160, stdin);
if (fgets(userInput[line], 6, stdin) == NULL)
{
break;
}
for (line = 0 ; line < 6; line++)
printf("line %d: %s\n", line, userInput[line]);
}
when i input 2 'hello' s
hello
hello
<ENTER> <- blank line
<ENTER> <- blank line
<ENTER> <- blank line
<ENTER> <- blank line
what i'm trying to figure out is if the user doesn't enter anything in the 3rd line i want it to print out the line they left blank and return the input, is there a way of doing this?
In the above code i have:
Code:
if (fgets(userInput[line], 6, stdin) == NULL)
{
break;
}
What i attempted here is if the line contains nothing then it should break out and exit. It doesn't seem to work though, it just keeps asking for input as usual without it