你好,我是一个初学者,我一直在代码中看到这个,但我无法弄清楚它到底意味着什么...... 就像下面的例子
#include<stdio.h>
int main(void)
{
char c1;
do
{
scanf_s("%c%*c", &c1, 1);
if ((c1>='a' && c1<='z')||(c1 >= 'A' && c1 <= 'Z'))
{
printf("%c %d", c1, c1);
}
} while (c1!=0);
return 0;
}
像这里一样它转换字符还是存储它的值? scanf 中的 (%*c) 对我来说是一个谜,据我所知,它有点对内存的引用,但不启动任何变量,它只是指向内存中存储的值...... 我说得对吗???
最佳答案
来自 C 标准(7.21.6.2 fscanf 函数)
3....After the %, the following appear in sequence:
— An optional assignment-suppressing character *.
— An optional decimal integer greater than zero that specifies the maximum field width (in characters).
— An optional length modifier that specifies the size of the receiving object.
— A conversion specifier character that specifies the type of conversion to be applied.
和(K.3.5.3.2 fscanf_s 函数)
4 The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a *)....
所以在这次通话中
scanf_s("%c%*c", &c1, 1);
格式%*c
禁止将读取的字符分配给参数。通常这种方法用于从缓冲区读取用户按 Enter 键后出现的换行符。
关于c - scanf 中 *variable 的用法以及为什么使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58803696/