以下是引用wangnihang在2015-11-9 15:01:13的发言:
大神指的是,scanf(%2c%3c 对应的char必须是字符串才合理么? 字符的话,会出错是么?
我从微软的msdn中找到两个代码片段
char c;
scanf("%c", &c);
char c[4];
scanf("%4c", c);
没仔细找,还是看C标准是怎么说的吧
1 if no field width is present in the directive
也就是 %c 其实等同于 %1c
the corresponding argument shall be a pointer to the initial element of a character array large enough to accept the sequence.
数组应当足够大,大到能容纳下该序列。
No null character is added.
尾部不添加'\0'