0

The scanner waits till we enter 100 bytes of data. So if we are redirecting a file into the executable's input, if the file has > 100 bytes of data. I scan it at one go, rather than line by line with fgets() or scanf("%s") etc.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
sharky
  • 327
  • 4
  • 13

1 Answers1

3

You can use fread to read the number of bytes you want, independent of line breaks or other whitespcae:

char buf[100];
size_t bytes_read = fread(buf, 1, 100, stdin);

Note that buf will not be null-terminated. So if you want to printf it, for instance (it needs a null terminated string), you can try the following:

char buf[101];
size_t bytes_read = fread(buf, 1, 100, stdin);
buf[100] = '\0'; // The 101th "cell" of buf will be
                 // the one at index `100` since the
                 // first one is at index `0`.
7heo.tk
  • 1,074
  • 12
  • 23
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220