I have a program where I need to scanf a string, which I know it will be only 2 characters long. (for example: \"ex\"). what is the proper way to do that?
I was goin
The proper way to limit the input using scanf() is
scanf()
if (scanf("%2s", myStr) != 1) /* error */;
But consider using fgets() rather than scanf()
fgets()
if (fgets(myStr, sizeof myStr, stdin) == NULL) /* error */;