I have:
#define MAX_STR_LEN 100
and I want to put into scanf pattern so I can control the string length:
scanf
Recommend the fgets(buffer, sizeof(buffer), stdin) approach.
If you still want to use scanf() you can create its format at runtime.
#define MAX_STR_LEN 100
char format[2 + sizeof(size_t)*3 + 4 + 1]; // Ugly magic #
sprintf(format, " %%%zu[^\n]", (size_t) MAX_STR_LEN);
scanf(format, sometext);
or re-define MAX_STR_LEN to be a string
#define MAX_STR_LEN "100"
scanf(" %" MAX_STR_LEN "[^\n]", sometext);
Still recommend the fgets().
Note fgets() will put leading spaces and the trailing \n in your buffer whereas " %[^\n]" will not.
BTW: the trailing s in your formats is not likely doing what you think.