Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Which format control string in C language can input numbers and characters?
Which format control string in C language can input numbers and characters?
Scanf (): Enter a string through the format controller% s. In addition to strings, scanf () can also enter other types of data. Scanf () reads strings separated by spaces. When it encounters a space, it is considered that the current string is over, so it is impossible to read the string containing the space.

Gets (): Enter the string directly, only the string can be entered. Gets () thinks that spaces are also part of a string, and string input ends only when the Enter key is encountered. So no matter how many spaces you enter, as long as you don't press Enter, it is the complete string of gets (). In other words, gets () is used to read a whole line of strings.

Extended data

Use of scanf () and gets ():

# include & ltstdio.h & gt

intmain(){

charstr 1[30]= { 0 };

charstr 2[30]= { 0 };

charstr 3[30]= { 0 };

//Get the usage of ()

printf(" input astring:");

gets(str 1);

//scanf () usage

printf(" input astring:");

scanf("%s ",str 2);

scanf("%s ",str 3);

printf("\nstr 1:%s\n ",str 1);

printf("str2:%s\n ",str 2);

printf("str3:%s\n ",str 3);

return0

}

Baidu Encyclopedia-Access

Baidu encyclopedia -—scanf