在C输入/输出扫描集 [英] Input/Output scanset in c

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

问题描述

#include<stdio.h>
int main()
{    
    char str[50]={'\0'};
    scanf("%[A-Z]s",str);  
    printf("%s",str);        
    return 0;
}

1)
输入:

1) Input:

的HelloWorld

helloWORLD

输出:

2)
输入:

2) Input:

的HelloWorld

HELLoworlD

输出:

HELL

在输出1,我所期望的输出为世界,但它没有给出任何outout。
从输出2,我明白,这是工作只有前几个字符都大写。

In output 1, i expected the output as "WORLD" but it didnt give any outout. From output 2, i understood that this is working only if the first few characters are in upper case.

能否请您解释一下它是如何工作?

Can you please explain how it actually works?

推荐答案

当你做

scanf("%[A-Z]s",str);

这需要输入你只要输入大写字母。
而且,由于将所有的数组'\\ 0'的printf()当遇到人会停止打印。

It takes input as long as you enter upper-case letters. And since you set all the array to '\0', printf() will stop printing when it meets one.

因此​​,第一输入是空的,而第二个是打印直到大写字符串的末尾。

Therefore, the first input is blank, and the second is printing until the end of the upper-case string.

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

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