C 中 scanf 中的扫描集行为 [英] Scanset behaviour in scanf in C

查看:62
本文介绍了C 中 scanf 中的扫描集行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 scanf 中使用 scanset 做一些事情,但卡在某个地方.

I tried to do some stuff with scanset in scanf but stuck somewhere.

我写的时候

char s1[250];
scanf("%[A-Z]",s1);

input : AHJHkiuy
Output: AHJH

有了这个,

scanf("%[^\n]",s1);

input: abcd ABCD hie
output: abcd ABCD hie       /*that is reading white space also (till \n) */

现在我的问题是,如果我输入:

Now My question is, if I give input as:

ABCDahaj ahajABCD ajak12347ab

并希望输出为:

ABCDahaj ahajABCD ajak

那么格式字符串应该怎么写呢?即这个scanset应该怎么用?

then how should the format string be written? That is, how should this scanset be used?

推荐答案

您可以稍微扩展您的示例并实现您的目标.

You could expand your example a little bit and achieve your goal.

scanf("%[A-Za-z ]", s1);

这篇关于C 中 scanf 中的扫描集行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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