Char, %c, won't print

Got some homework I'm working on and I'm having issues getting a char datatype to display, or maybe it's not reading the input prompt. I've tried a dozen different ways of writing this and it still won't display.

#include <stdio.h>


int main(void)
{
char grade;

printf("Enter in a grade: A, B, C, D, or F \n");
scanf_s("%c", &grade);

printf("I expect my grade to be %c in this class. \n", grade);

return 0;
}
You're using the weird "safe" version of scanf (and I use the word "safe" only because that's what the 's' stands for).

My advice: don't use it. Use the normal scanf. IE: use scanf, not scanf_s:

 
scanf("%c", &grade); // <- this will work fine 



If you must use scanf_s, then you need to supply the size of the data being read:

 
scanf_s("%c", &grade, 1); // <- this will also work 
Great! That worked with the ', 1' at the end. My compiler won't let me use regular scanf and prompts with an "error C4996" and is forcing me to use scanf_s which we obviously haven't covered in class.

I truly appreciate your help on this.
My compiler won't let me use regular scanf and prompts with an "error C4996" and is forcing me to use scanf_s which we obviously haven't covered in class.


I really hate that about VS. But it's fixable.

The easiest way to fix it is to put this at the top of your file:

 
#define _CRT_SECURE_NO_WARNINGS 
Ah gotcha. That's stupid to have to include that for each program I'll be writing.
I agree. Fortunately for me, I primarily code C++ and not C, so I don't use these functions often.
Topic archived. No new replies allowed.