Say I have a character array:
#define LEN 10
char arr[LEN + 1];
Lets do some scanf operation to it:
scanf("Name: %s", arr);
This could be dangerous if someone is typing a name that is longer than 10 characters. So better use this:
scanf("Name: %10s", arr);
Well now I would run into trouble if LEN
is changed. I would have to go through the whole code to correct every line where I used the 10
in context of arr
. So I thought about somehting like this:
scanf("Name: %LENs", arr);
But this will not work.LEN
is not resolved by the preprocessor beacuse it is used inside a string.
How to use a define inside a format string?