You can use the C preprocessor to help you with that.
#define STR2(x) #x
#define STR(X) STR2(X)
scanf("%" STR(MAXVAL) "s", string);
The processor combines "%" STR(MAXVAL) "s"
to "%5s"
More Related Contents:
- How do you type something on the same line of text in C [closed]
- What can I use for input conversion instead of scanf?
- Disadvantages of scanf
- How to use sscanf in loops?
- Why does scanf ask twice for input when there’s a newline at the end of the format string?
- C: Multiple scanf’s, when I enter in a value for one scanf it skips the second scanf [duplicate]
- Why does reading into a string buffer with scanf work both with and without the ampersand (&)?
- When should I use ampersand with scanf()
- scanf: “%[^\n]” skips the 2nd input but ” %[^\n]” does not. why?
- What does space in scanf mean? [duplicate]
- Reading a line using scanf() not good?
- How to scanf only integer?
- What will happen if ‘&’ is not put in a ‘scanf’ statement?
- Does scanf() take ‘\n’ as input leftover from previous scanf()?
- printf not printing on console
- Problems with C scanf(“%c”) function to read characters one by one
- Going through a text file line by line in C
- difference between %ms and %s scanf
- Reading a single character in C
- What does `scanf(“%*[^\n]%*c”)` mean?
- Get scanf to quit when it reads a newline?
- C – trying to read a single char from stdin (and failing) w/ scanf / getchar
- scanf(“%c”) call seems to be skipped
- Strange character after an array of characters
- While-loop ignores scanf the second time
- Using scanf and fgets in the same program?
- What are scanf(“%*s”) and scanf(“%*d”) format identifiers?
- How do you read scanf until EOF in C?
- What is the difference between %f and %lf in C?
- Difference between scanf() and fgets()