| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3739 人关注过本帖, 1 人收藏
标题:scanf("%*[^\n]%*c");这是什么意思?
只看楼主 加入收藏
wujingqian
Rank: 1
来 自:遥远的星球
等 级:新手上路
帖 子:77
专家分:2
注 册:2008-3-12
结帖率:100%
收藏(1)
 问题点数:0 回复次数:6 
scanf("%*[^\n]%*c");这是什么意思?
源码:
int data[2];
bool Input()
{
    int *p=data;
    *p=*(p+1)=0;
    char ch;
    if(EOF==scanf(" %c", &ch))
        exit(0);   
    while (ch!='\n')
    {
        if (ch==' ') {
            ++p;
            scanf(" %c", &ch);
        }
        *p=*p*10+ch-'0';
        if(*p>1000000) {
            scanf("%*[^\n]%*c");
            return false;
        }
        ch=getchar();
    }
    p=data;
    if (*p>*(1+p)) swap(*p, *(p+1));
    if (*p<1||*(p+1)>1000000) return false;
    return true;
}
搜索更多相关主题的帖子: scanf 
2008-06-05 14:00
金罡
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-6-4
收藏
得分:0 
百度一下就知道了

欢迎长期在线的编程爱好都加入此群: 21135958
2008-06-05 15:34
hackerjiang
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:3
帖 子:780
专家分:111
注 册:2007-4-27
收藏
得分:0 
~~~

(づ ̄ 3 ̄)づ
2008-06-05 15:36
wujingqian
Rank: 1
来 自:遥远的星球
等 级:新手上路
帖 子:77
专家分:2
注 册:2008-3-12
收藏
得分:0 
我查不到,才来发帖子的。想请高手教教
2008-06-05 15:51
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
这个和unix下的正则表达式很相似
[ ]表示选择,^表示非
这里的*是忽略

The format specification controls how the arguments are converted for assignment. The percent sign (%) indicates the start of a conversion specification. Except for the conversion specifications and white space, other characters in the format have to match the input. If a character doesn't match, processing stops, leaving the remainder of the input unread.

There are three optional components to a conversion specification, shown in square brackets below:

    %[*][fldwidth][lenmodifier]convtype


The optional leading asterisk is used to suppress conversion. Input is converted as specified by the rest of the conversion specification, but the result is not stored in an argument.

The fldwidth component specifies the maximum field width in characters. The lenmodifier component specifies the size of the argument to be initialized with the result of the conversion. The same length modifiers supported by the printf family of functions are supported by the scanf family of functions (see Figure 5.8 for a list of the length modifiers).

The convtype field is similar to the conversion type field used by the printf family, but there are some differences. One difference is that results that are stored in unsigned types can optionally be signed on input. For example, 1 will scan as 4294967295 into an unsigned integer. Figure 5.10 summarizes the conversion types supported by the scanf family of functions.

Conversion  type       Description

d                      signed decimal, base 10

i                      signed decimal, base determined by format of input

o                      unsigned octal (input optionally signed)

u                      unsigned decimal, base 10 (input optionally signed)

x                      unsigned hexadecimal (input optionally signed)

a,A,e,E,f,F,g,G           floating-point number

c                      character (with l length modifier, wide character)

s                      string (with l length modifier, wide character string)

[                      matches a sequence of listed characters, ending with ]

[^                     matches all characters except the ones listed, ending with ]

p                     pointer to a void

n                     pointer to a signed integer into which is written the number of characters read so far

%                     a % character

C                     wide character (an XSI extension, equivalent to lc)

S                     wide character string (an XSI extension, equivalent to ls)

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-06-05 16:22
wujingqian
Rank: 1
来 自:遥远的星球
等 级:新手上路
帖 子:77
专家分:2
注 册:2008-3-12
收藏
得分:0 
有没有中文的,我ENGLISH很烂啊
2008-06-05 19:53
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
没见过像你这么懒的,帮你搜出来了还要再给你找中文的。
这种简单的英文都看不懂就不用搞计算机了。
找本字典一个一个的查,态度决定高度。

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-06-05 20:09
快速回复:scanf("%*[^\n]%*c");这是什么意思?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017017 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved