#line input in C

19 messages · Page 1 of 1 (latest)

hushed crystal
#

scanf("%[^\n]1000s", line)

#

what does [^\n]1000 mean ???

marsh zealot
#

This format specifier tells scanf to read input until a newline character (\n)

modern vortex
#

Well, since char line array is set to 1000, i assume 1000s means the limit?

marsh zealot
#

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.

quasi wagonBOT
#

@marsh zealot has reached level 1. GG!

hushed crystal
marsh zealot
#

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);

hushed crystal
quasi wagonBOT
#

@hushed crystal has reached level 1. GG!

hushed crystal
marsh zealot
#

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.

hushed crystal
#

oh ok i get it now

#

thnx

#

.close

#

!close

vagrant apex