Hello all,
Okay I'm stumped. I must be misreading something, but I think the below program should print "1" as the result of sscanf. That is, I believe searching for "t%c" would catch the character "h" in the below example, but I can't figure out why it always returns 0.Any ideas?
I hate just flat-out asking for the answer but it seems I fundamentally misunderstand either the syntax or the sscanf function itself. Thanks for any hints or pointers.Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[], char *envp[]) { /* we only care if sscanf found our substring, we don't care what it's value is */ char *junk; junk = (char *) malloc (25); /* allocate our memory */ /* why doesn't this return 1? t%c is within "Hello there", should read 'h' */ printf("\nsscanf returned: %i\n", sscanf("Hello there", "t%c", junk)); free (junk); /* free up our memory */ return (0); /* always return success */ } /* end main(...) */
Josh



LinkBack URL
About LinkBacks
Any ideas?


