July 14th, 2013, 07:06 PM
Scanning a full line and scanning a double/int
comparing these two programs
char x; // could also be int or double
printf("x = %c\n", x);
the first one doesn't wait for the getchar, but the second one does.
I know that there's a \n in the buffer after scanning a double, int, char variable, which is why getchar automatically reads it
but the program does wait for getchar in the second program. on the other hand, when I output the string, the string doesn't have a newline at the end.
does this mean that gets reads \n, but takes it only as a signal to end the reading, and doesn't store it in the string?
July 14th, 2013, 11:45 PM
> does this mean that gets reads \n, but takes it only as a signal to end the reading, and doesn't store it in the string?
That's exactly what it does, if you had read the manual page to find out.
Now, having read how it works, you must then erase it from your mind and NEVER use it again.
Please stick to using fgets() from now on.
As in say