是什么作为格式说明scanf函数%* C%c和%C之间的区别? [英] What is the difference between %*c%c and %c as a format specifier to scanf?

查看:206
本文介绍了是什么作为格式说明scanf函数%* C%c和%C之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常获得与%C 一个人物,但我所看到code,它使用%* C%C 。例如:

I typically acquire a character with %c, but I have seen code that used %*c%c. For example:

char a;
scanf("%*c%c", &a);

有什么区别?

推荐答案

scanf函数格式字符串,在 * 字符是的分配燮pressing字符

In a scanf format string, after the %, the * character is the assignment-suppressing character.

在你的榜样,它吃的第一个字符,但不保存它。

In your example, it eats the first character but does not store it.

例如有:

char a;
scanf("%c", &a);

如果你输入: XYZ \\ n \\ n 是新行字符),那么 X 将被存储在对象 A

If you enter: xyz\n, (\n is the new line character) then x will be stored in object a.

使用:

scanf("%*c%c", &a);

如果你输入: XYZ \\ n 将被存储在对象 A

If you enter: xyz\n, y will be stored in object a.

ç说指定了 * scanf函数是这样的:

C says specifies the * for scanf this way:

(C99,7.19.6.2p10)除非转让SUP pression是由*指出,转换的结果被放置在目标指向第一个参数如下一个尚未收到的格式参数转换结果。

(C99, 7.19.6.2p10) Unless assignment suppression was indicated by a *, the result of the conversion is placed in the object pointed to by the first argument following the format argument that has not already received a conversion result.

这篇关于是什么作为格式说明scanf函数%* C%c和%C之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆