I usually use the definition for string size, but when I use scanf()
, I want to protect the function from reading too many characters (and reserve space for the null terminator). I was wondering if I can do this using my define, and not a hard-coded magic number ...
#include <stdio.h>
#define MAXLEN 4
int main(void) {
char a[MAXLEN];
scanf("%3s", a);
}
Is it possible? If so, how?
source
share