Guard scanf from reading too many characters with a define? [duplicate]
问题 This question already has answers here : scanf() variable length specifier (4 answers) Closed 2 years ago . Usually, I use a define for the size of a string, but when I use scanf() , I want to guard the function from reading too many characters (and reserve space for the null-terminator). I was wondering whether I could do this using my define, instead of a hardcoded magic number... #include <stdio.h> #define MAXLEN 4 int main(void) { char a[MAXLEN]; scanf("%3s", a); // Can I do that with