new things for me

Dec 14, 2011 at 3:54pm
can someone please tell me what does these sign means??
"%d","%19","%[^\n" and stdin???
Dec 14, 2011 at 4:04pm
I don't know about the last two but the first shouldn't matter if you are writing in proper c++ syntax. However, it is used as arguements for scanf and printing variable values in printf
Dec 14, 2011 at 4:30pm
I'm guessing this is for sprintf()?
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

As for the last one:
http://www.cplusplus.com/reference/clibrary/cstdio/stdin/

Not sure about this one "%[^\n". Although, "\n" or '\n' are for new lines. The same as pressing Enter within a text editor.
Last edited on Dec 14, 2011 at 4:31pm
Dec 14, 2011 at 4:57pm
That last one looks like regex.
Dec 14, 2011 at 7:14pm
"%[^\n]" is a format specifier for the scanf() family of functions, which instructs it to read successive characters from the input until the end of line (or end of input), storing them in successive positions of a character array. Pointer to the first element of that character array is expected as the argument to such scanf(). After reaching the \n or end of input, scanf() will store an additional null character in the array. The \n will remain in the input stream, unprocessed.

Note that just like %s, this format specifier should never be used without providing the length of the buffer (minus one, to account for the null), e.g.

1
2
3
4
5
6
7
#include<stdio.h>
int main()
{
    char s[10];
    scanf("%9[^\n]", s);
    puts(s);
}

demo: http://ideone.com/drysN
Last edited on Dec 14, 2011 at 7:20pm
Topic archived. No new replies allowed.