当前位置: 代码迷 >> C语言 >> scanf("%*[^\n]%*c");这是什么意思?
  详细解决方案

scanf("%*[^\n]%*c");这是什么意思?

热度:984   发布时间:2008-06-05 14:00:16.0
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  

----------------解决方案--------------------------------------------------------
百度一下就知道了
----------------解决方案--------------------------------------------------------
~~~
----------------解决方案--------------------------------------------------------
我查不到,才来发帖子的。想请高手教教
----------------解决方案--------------------------------------------------------
这个和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)
----------------解决方案--------------------------------------------------------
有没有中文的,我ENGLISH很烂啊
----------------解决方案--------------------------------------------------------
没见过像你这么懒的,帮你搜出来了还要再给你找中文的。
这种简单的英文都看不懂就不用搞计算机了。
找本字典一个一个的查,态度决定高度。
----------------解决方案--------------------------------------------------------
  相关解决方案