How to control the number of chars read in a string by using scanf()?
- You can control the number of chars read in a string by using format specifier.
Example:char buf[25];
scanf("%20s", buf);
- Doing this limits the length of the characters that will be read by scanf() to 20 characters maximum although the buffer can hold 25 characters.
- The scanf() stores the results away in variables which you provide in the argument list.
- It reads the data from the console or from a FILE stream and parses it.