plz tell me what does line means:
scanf ("%[^\n]s",char);
and some variants like: "%*s" and "%*s%s"
plz correct if any thing is wrong..
plz tell me what does line means:
scanf ("%[^\n]s",char);
and some variants like: "%*s" and "%*s%s"
plz correct if any thing is wrong..
I think this is a bad scanf line:
scanf ("%[^\n]s",char);
and there are other reasons besides.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I presume you would already know the purpose of scanf
[^\n] implies to accept every character except newline character '\n'
in the string named char(note that keywords are not allowed as variable names);
It is called as circumflex if i remember correctly.
%*s is assignment suppression operator.
A string is read from the console but not stored in any variable.
BTW,When using scanf to read strings you should be careful and specify the size of string in
the format string to avoid buffer overflow exploits.
Below link explains how to use scanf:
http://cboard.cprogramming.com/showp...37&postcount=9
Last edited by stevesmithx; 11-30-2008 at 06:17 AM. Reason: add link
Not everything that can be counted counts, and not everything that counts can be counted
- Albert Einstein.
No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
- Herbert Mayer
Ooops! Thanks steve.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
you're welcome.
Not everything that can be counted counts, and not everything that counts can be counted
- Albert Einstein.
No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
- Herbert Mayer
Generally scanf can take only single word of input. it wont take multi-word input.
scanf("%[^\n]s", char1) > allows us to input multiple words to char1. (in my first post i have used char just to stress on the character inputs, i did not mean to use any keyword as variable..)...
But masking \n should allow the compiler to ignore only \n input, but when we press Enter the input ends. Whereas, it allows the compiler to mask any space(space, tab) and we can store multiple words. can u plz tell me why is it so?
Also can u give a small example where this is used?