I
I
Ingvar Von Bjork2016-11-24 12:41:07
C++ / C#
Ingvar Von Bjork, 2016-11-24 12:41:07

How to make scanf work?

When using scanf, it gives an error:

char str;
printf("qwe");
scanf("%s", &str);
return 0;

Ошибка	2	error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.	e:\decanat\consoleapplication15\consoleapplication15\consoleapplication15.cpp	11	1	ConsoleApplication15

After adding
#define _CRT_SECURE_NO_WARNINGS
nothing changes.
And when using scanf_s, the program starts, but after entering the value, it throws the following error:
dadd1062d568496b8a2b5a511177299f.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ingvar Von Björk, 2016-11-24
@DeboshiR

Everything turned out to be easier - you need to disable SDL.

M
MiiNiPaa, 2016-11-24
@MiiNiPaa

After adding nothing changes.

You need to add it at the very beginning of the file, before connecting any header files.
And most importantly: you have one char that has room for one character. When reading into %s, at least two will be stored - a character and a trailing 0.

A
abcd0x00, 2016-11-27
@abcd0x00

This is Visual Studio blocking ssh functions, suggesting its own functions instead of sish ones.
Must be added at the very beginning (before all lines)
#define _CRT_SECURE_NO_WARNINGS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question