-3
char variable[20][200];
printf("Enter Strings\n");
for (i = 0; i < 10 ;i++)  
scanf("%100s", variable[i]); 

What is the function and operation logic of scanf(%100s) in here? I searched this command and i found some codes but i did not understand how it's working

  • 1
    https://stackoverflow.com/questions/12306591/read-no-more-than-size-of-string-with-scanf – Mat May 01 '18 at 13:49
  • [man scanf](https://linux.die.net/man/3/scanf). Read starting from "*The conversion specifications in format are of two forms...*" – Eugene Sh. May 01 '18 at 13:50
  • @Mat Except that's approaching the question from the other direction - how to limit the length read. This question is based on not knowing that the `100` is a length limitation. And I've yet to find an actual duplicate here on Stackoverflow, although at least one probably does exist. – Andrew Henle May 01 '18 at 13:54

1 Answers1

3

Here, the 100 is the length modifier, used in the conversion specifier. A length modifier specifies the size of the receiving object.

In this case, the mention of 100 limits the effective input size to be scanned to 100, which helps prevents buffer overflow in the destination due to overly long input.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261