c language scanf can’t input

c language scanf can not enter the value

scanf () is the C language standard library input function, the declaration is included in the stdio.h file, so in order to use the function, you must load the #include<stdio.h> header file. When executing to the scanf function, the program pauses to wait for user input, the function only accepts the address of the variable, in the format & variable name. Is a blocking function, such as the user input is complete, then the value will be assigned to the variable, so that the function call is complete. Knock the Enter key to inform the computer to type finished.

Function prototype: intscanf(constchar*format, …) ;

Description: scanf () is a general-purpose subroutine that reads the contents from the standard input stream stdio (standard input device, usually the keyboard), which can be illustrated to read in multiple characters in the format and save them in a variable at the corresponding address.

It is called in the form: scanf(“<format description string>”, <variable address>); the variable address is required to be valid and in the same order as the format description.

Example of use:

// Use the scanf function to enter a character variable.

chara;

scanf(“%c”,&a);

//Input multiple values simultaneously.

scanf(“%d,%d”,&num1,num2);

//Can’t use the \n escape character internally, otherwise it’s endless.

scanf(“%d\n”,&a);

c language topic why I used scanf input in the pop-up dialog box did not respond?

C language input function scanf improper use, there will be a variety of errors, the correct use, will improve efficiency, is now some precautions, the correct way to use and experience to share with you.

In C language blank characters include: space, line feed (

), carriage return (

), horizontal tab ( ), page break ( ), vertical tab ( ). When one of the parameters read by scanf is a number, the blank characters at the beginning of the input are ignored, and the reading of the number is stopped until the first character encountered is not a number; when reading a string, the blank characters at the beginning are also ignored, and the reading of the characters [0-9a-zA-Z….] (a variety of displayable characters), until the encounter is not a character to stop matching, (including blank characters, usually a carriage return line feed), and add the empty character at the end of the string, (the empty character is the end of the string output character). scanf encountered when the stop character to stop the character is also put into the keyboard character cache area

C program running scanf function input character error?

scanf() does not check boundaries when reading, so it may cause memory leaks, so VS2013 provides scanf_s() instead, when calling it, you must provide scanf_s with a number to indicate how many bits of the character to read, the usage is scanf_s(“%c”,&letter,sizeof( letter)), otherwise, even if Ctrl+F7 and Ctrl+F5 are passed, the program may run very differently from what you expect.

If you have to use the scanf function, you can disable the warning in two ways:

(1) Right-click on the project – Properties – C/C++- -Preprocessor – Add _CRT_SECURE_NO_WARNINGS to the preprocessor definition, then tap OK to exit.

(2) Define at the top of the function: #define_CRT_SECURE_NO_WARNINGS, which also disables error reporting warnings.