user-0 提问: C语言最基础的缓冲区问题

回复:
user: user-1
content: 引用 8 楼 voidth 的回复:英文不好看不懂。。。 我问题没说明白。 scanf后 缓冲区留下的 \n 下一个scanf %s 执行时 略去 空白符 略去的意思是 \n依然存在   只是scanf忽略 还是scanf把 \n从缓冲中清除？  咋说不明白呢。。。就是清除了。随着第二个scanf处理完它的输入数据，然后这些输入数据包括之前的回车，都清除掉了

user: user-2
content: 英语也是一门计算机语言的说。

user: user-0
content: 英文不好看不懂。。。 我问题没说明白。 scanf后 缓冲区留下的 \n 下一个scanf %s 执行时 略去 空白符 略去的意思是 \n依然存在   只是scanf忽略 还是scanf把 \n从缓冲中清除？

user: user-0
content: 那就是 第一个scanf("%d",&p->number);输入后 缓冲区留下\n 第二个scanf("%s",p->name);    前面的\n就从缓冲区消失了？

user: user-1
content: 引用 4 楼 voidth 的回复:刚才用电脑试了下  全局结构体的的元素不是初始化的。。。  scanf本身会滤除前导空白（包括回车符） 除非 %c,  这滤除是指的从缓冲区 清除掉  还是指无视掉  全局变量，编译器会保证都初始化成0  清除掉和无视掉没有区别，因为会接着处理后面的数据，这样的话，之前的数据最后也都一起清除了

user: user-2
content: Format Specification Fields: scanf and wscanf Functions A format specification has the following form:  % [width] [{h | l | I64 | L}]type  The format argument specifies the interpretation of the input and can contain one or more of the following:   White-space characters: blank (' '); tab ('\t'); or newline ('\n'). A white-space character causes scanf to read, but not store, all consecutive white-space characters in the input up to the next non–white-space character. One white-space character in the format matches any number (including 0) and combination of white-space characters in the input.   Non–white-space characters, except for the percent sign (%). A non–white-space character causes scanf to read, but not store, a matching non–white-space character. If the next character in stdin does not match, scanf terminates.   Format specifications, introduced by the percent sign (%). A format specification causes scanf to read and convert characters in the input into values of a specified type. The value is assigned to an argument in the argument list.  The format is read from left to right. Characters outside format specifications are expected to match the sequence of characters in stdin; the matching characters in stdin are scanned but not stored. If a character in stdin conflicts with the format specification, scanf terminates, and the character is left in stdin as if it had not been read.  When the first format specification is encountered, the value of the first input field is converted according to this specification and stored in the location that is specified by the first argument. The second format specification causes the second input field to be converted and stored in the second argument, and so on through the end of the format string.  An input field is defined as all characters up to the first white-space character (space, tab, or newline), or up to the first character that cannot be converted according to the format specification, or until the field width (if specified) is reached. If there are too many arguments for the given specifications, the extra arguments are evaluated but ignored. The results are unpredictable if there are not enough arguments for the format specification.  Each field of the format specification is a single character or a number signifying a particular format option. The type character, which appears after the last optional format field, determines whether the input field is interpreted as a character, a string, or a number.   The simplest format specification contains only the percent sign and a type character (for example, %s). If a percent sign (%) is followed by a character that has no meaning as a format-control character, that character and the following characters (up to the next percent sign) are treated as an ordinary sequence of characters, that is, a sequence of characters that must match the input. For example, to specify that a percent-sign character is to be input, use %%.  An asterisk (*) following the percent sign suppresses assignment of the next input field, which is interpreted as a field of the specified type. The field is scanned but not stored.

user: user-0
content: 刚才用电脑试了下  全局结构体的的元素不是初始化的。。。  scanf本身会滤除前导空白（包括回车符） 除非 %c,  这滤除是指的从缓冲区 清除掉  还是指无视掉

user: user-0
content: 那就是后面的scanf会清除  前面缓冲区scanf的回车了是么  我还有一个问题  顺便问一下 要构建链表 typedef struct info{ 	int number; 	char name[10]; 	int sex;//0男1女 	int grade; 	struct info* next; }student; 定义全局的结构体变量 里面数据域的值是0么 里面的指针域的指针是指向空么

user: user-3
content: scanf本身会滤除前导空白（包括回车符） 除非 %c, 而表示输入完成的回车， 通常会在一次输入数据的时候，输入回车， 此回车会留在缓冲区内 getchar(),gets 不会会滤除前导空白 所以只需要一个 getchar();

user: user-4
content: scanf("%d\n",&p->grade);