Ekran Goruntusu 179

Scanf is not working in Microsoft visual studio code (Solution )

Scanf is not working in Microsoft visual studio code

One of the problems encountered after the installation of the programing language C in Microsoft Visual Studio sometimes the number lines are not displayed automatically which you have to do it manually.

To solve this we are going to write a program:

Where we are going to write a program where we are going to ask someone’s age by asking his birth year.

Ekran Goruntusu 178

After you run your code you have a message saying :

“Return value ignored: ‘scanf’ “

“  ‘scanf’ : this function or variable may be unsafe ”


To solve this you have to add this code #pragma warning(disable:4996)

The green line in the scanf code will still but your code will run without any problem.

#pragma warning(disable:4996)

The output after running the code this time 


#pragma warning(disable:4996)

To turn off the warning within a file for everything that follows, use the warning pragma.

If you want  you can   copy the code from here :

int  age;

int birth_year;

printf(” Enter your birthyear “);

scanf(“%d”, &birth_year);

age = 2022 – birth_year;

printf(” your age is = %d\n “, age);

3 thoughts on “Scanf is not working in Microsoft visual studio code (Solution )”

  1. Thank you so much,
    I’ve been having this problem and couldn’t find a solution anywhere on the internet.
    Would you mind giving an explanation as to how this works?

  2. Pingback: Visual Studio Scanf | How To Solve Scanf() Error Problem In Microsoft Visual Studio 11784 좋은 평가 이 답변

Leave a Comment

Your email address will not be published. Required fields are marked *