请问一下c语言scanf中的意思
答案:5 悬赏:0 手机版
解决时间 2021-02-02 04:39
- 提问者网友:不爱我么
- 2021-02-01 10:53
请问一下大家那个那个SCANF在C语言中的意思!然后就是在什么情况下需要用到它!谢谢
最佳答案
- 五星知识达人网友:洒脱疯子
- 2021-02-01 10:59
scanf()函数根据由format(格式)指定的格式从stdin(标准输入)读取,并保存数据到其它参数. 它和printf()有点类似. format(格式)字符串由控制字符,空白字符和非空白字符组成. 控制字符以一个%符号开始,如下: 控制字符说明%c一个单一的字符%d一个十进制整数%i一个整数%e, %f, %g一个浮点数%o一个八进制数%s一个字符串%x一个十六进制数%p一个指针%n一个等于读取字符数量的整数%u一个无符号整数%[]一个字符集%%一个精度符号scanf()读取匹配format(格式)字符串的输入. 当读取到一个控制字符, 它把值放置到下一个变量. 空白(tabs, 空格等等)会跳过. 非空白字符和输入匹配, 然后丢弃. 如果是一个在%符号和控制符间的数量, 那么只有指定数量的字符转换到变量中. 如果scanf()遇到一个字符集(用%[]控制字符表示), 那么在括号中的任意字符都会读取到变量中. scanf()的返回值是成功赋值的变量数量, 发生错误时返回EOF.
全部回答
- 1楼网友:痴妹与他
- 2021-02-01 14:00
格式化输入当你的程序需要用户输入字符或数字是会用到
- 2楼网友:孤独入客枕
- 2021-02-01 13:26
SCANF的意思是要求用户或者是从文件向输入流进行输入。
- 3楼网友:零点过十分
- 2021-02-01 12:03
是scanf,C语言是区分大小写的,如果是SCANF,那估计是自定义的一个标识符,scanf是格式化输入,可从键盘接收用户的输入。
- 4楼网友:底特律间谍
- 2021-02-01 11:17
格式化输入用的,你需要 “格式化” 的输入时,就用,比如输入一个字符串,或者一个整数 这是unix下的联机手册:(部分扥)Name
scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf - input format conversion Synopsis
#include
int scanf(const char *format, ...);
int fscanf(FILE *stream, const char *format, ...);
int sscanf(const char *str, const char *format, ...);#include
int vscanf(const char *format, va_list ap);
int vsscanf(const char *str, const char *format, va_list ap);
int vfscanf(FILE *stream, const char *format, va_list ap);
Description
[AD] The scanf() family of functions scans input according to format as described below. This format may contain conversion specifications; the results from such conversions, if any, are stored in the locations pointed to by the pointer arguments that follow format. Each pointer argument must be of a type that is appropriate for the value returned by the corresponding conversion specification. If the number of conversion specifications in format exceeds the number of pointer arguments, the results are undefined. If the number of pointer arguments exceeds the number of conversion specifications, then the excess pointer arguments are evaluated, but are otherwise ignored. The scanf() function reads input from the standard input stream stdin, fscanf() reads input from the stream pointer stream, and sscanf() reads its input from the character string pointed to by str. The vfscanf() function is analogous to vfprintf(3) and reads input from the stream pointer stream using a variable argument list of pointers (see stdarg(3). The vscanf() function scans a variable argument list from the standard input and the vsscanf() function scans it from a string; these are analogous to the vprintf() and vsprintf() functions respectively. The format string consists of a sequence of directives which describe how to process the sequence of input characters. If processing of a directive fails, no further input is read, and scanf() returns. A "failure" can be either of the following: input failure, meaning that input characters were unavailable, or matching failure, meaning that the input was inappropriate (see below). A directive is one of the following: *
A sequence of white-space characters (space, tab, newline, etc; see isspace(3)). This directive matches any amount of white space, including none, in the input. * An ordinary character (i.e., one other than white space or '%'). This character must exactly match the next character of input. * A conversion specification, which commences with a '%' (percent) character. A sequence of characters from the input is converted according to this specification, and the result is placed in the corresponding pointer argument. If the next item of input does not match the the conversion specification, the conversion fails - this is a matching failure. Each conversion specification in format begins with either the character '%' or the character sequence "%n$" (see below for the distinction) followed by:
*
An optional '*' assignment-suppression character: scanf() reads input as directed by the conversion specification, but discards the input. No corresponding pointer argument is required, and this specification is not included in the count of successful assignments returned by scanf(). * An optional 'a' character. This is used with string conversions, and relieves the caller of the need to allocate a corresponding buffer to hold the input: instead, scanf() allocates a buffer of sufficient size, and assigns the address of this buffer to the corresponding pointer argument, which should be a pointer to a char * variable (this variable does not need to be initialised before the call). The caller should subsequently free(3) this buffer when it is no longer required. This is a GNU extension; C99 employs the 'a' character as a conversion specifier (and it can also be used as such in the GNU implementation). * An optional decimal integer which specifies the maximum field width. Reading of characters stops either when this maximum is reached or when a non-matching character is found, whichever happens first. Most conversions discard initial whitespace characters (the exceptions are noted below), and these discarded characters don't count towards the maximum field width. String input conversions store a null terminator ('\0') to mark the end of the input; the maximum field width does not include this terminator. * An optional type modifier character. For example, the l type modifier is used with integer conversions such as %d to specify that the corresponding pointer argument refers to a long int rather than a pointer to an int. * A conversion specifier that specifies the type of input conversion to be performed. The conversion specifications in format are of two forms, either beginning with '%' or beginning with "%n$". The two forms should not be mixed in the same format string, except that a string containing "%n$" specifications can include %% and %*. If format contains '%' specifications then these correspond in order with successive pointer arguments. In the "%n$" form (which is specified in POSIX.1-2001, but not C99), n is a decimal integer that specifies that the converted input should be placed in the location referred to by the n-th pointer argument following format.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯