#line input in C
19 messages · Page 1 of 1 (latest)
This format specifier tells scanf to read input until a newline character (\n)
what about 1000 ?
Well, since char line array is set to 1000, i assume 1000s means the limit?
There is no such format specifier as 1000s. If the intention is to limit the input size to 1000 characters, you should specify it as part of the %[^\n] format specifier.
@marsh zealot has reached level 1. GG!
so that line is incorrect ?
If you want to read a line of input up to 999 characters, the corrected code would look like this
char line[1000];
scanf("%999[^\n]", line);
but the code didn't throw any error when i ran it ?
@hushed crystal has reached level 1. GG!
C is a language that allows a lot of flexibility, which can sometimes result in unexpected behavior or bugs if the code isn't written properf
C compilers generally don't check the exact format specifiers passed to scanf as long as they look somewhat valid.
I would call it freedom ðŸ˜