![]() |
what "%[^_]_" this refers to in sscanf
Hi
can some exaplin me wat WHAT and HOW this sacanf function is working sscanf(NAME(img), "%[^_]_%[^_]_%[^_]_%[^_]_%d.%[^_]", userid, head, expression, eyes, &scale, photo); its used here Code:
load_target(img, net)Code:
#define NAME(img) ((img)->name)i understand the functioning of scanf like in this Code:
sscanf(line, "%d %d", &nc, &nr);BUT i am not able to understand what wil this refer to %[^_]_ and what wil it store in userid and ither mentioned as in sscanf(NAME(img), "%[^_]_%[^_]_%[^_]_%[^_]_%d.%[^_]", userid, head, expression, eyes, &scale, photo); Thankyou |
Re: what "%[^_]_" this refers to in sscanf
The square brackets are a special form of the 's' specifier. They are similar to square brackets used in a regex expression. They define a class of characters for scanf to match. For example, %[abc] asks scanf to capture the character if it is an 'a' OR a 'b' OR a 'c', and stash it in our specified variable. The '^' character has the effect of inverting the request. For example, %[^abc] asks scanf to capture the character if it is NOT an 'a' or 'b' or 'c'.
This is documented in your material regarding 'scanf'. You might want to read that. |
Re: what "%[^_]_" this refers to in sscanf
All that i know about %[^_]is that it is used to scan a particular line includeing the blank spaces or nul values..... This syntax is used in printf..... Also DaWei has given a very good and explanation..... I loved it...
|
Re: what "%[^_]_" this refers to in sscanf
The bracket format is NOT used by printf. Where would be the utility of such a thing? Please try to avoid disseminating bogus information.
|
Re: what "%[^_]_" this refers to in sscanf
Using this [^] (^ caret Symbol ) we can get the input till the character from the keyboard....
for Example.... U can get a line(Till \n is reached) by using Scanf insted of gets(); U can give any character [^ #] ....[^_] char *a=(char*)malloc(sizeof(char)); scanf("%[^\n]",char); |
Re: what "%[^_]_" this refers to in sscanf
Unfortunately, your code will trash the heap. You only malloc'ed one char. Scanf will return anything entered BUT the newline. Malloc for a single char is hideously inefficient, and the overhead for managing that memory will be many times as large as the single char. Additionally, you have an error here:
Code:
scanf("%[^\n]",char); |
| All times are GMT +5.5. The time now is 11:44. |