If I put:
#define SIZE 10
and after:
scanf("%SIZEs", s);
I have a runtime error. The preprocessor should substitute SIZE with 10 before to compile, so this should equal (in my opinion) to write
scanf("%10s", s);
so, where is the mistake?
It is not possible to replace the contents of the string literal by macro.
For example, it does the following:
#include <stdio.h>
#define S_(x) #x
#define S(x) S_(x)
#define SIZE 10
int main(void){
    char s[SIZE + 1];
    scanf("%" S(SIZE) "s", s);
    puts(s);
    return 0;
}
                        In your code, the problem is in
  scanf("%SIZEs", s);
Anything residing between the quotes " " of a format string (string literal, in general) will not get substituted through MACRO substitution. 
So, your scanf() remains the same as you're written, after preprocessing, and %S (or, %SIZEs, in whole) being one invalid format specifier, you get into  undefined behaviour and hence got the error.
You can try the workaround as
 scanf("%"SIZE"s", s);
This way, SIZE will be outside the quotes and will be considered for substitution in preprocessing stage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With