I have problems with sscanf. To test this, I made a simple file, so when I compile this:
#include <stdio.h>
main(){
char *a;
char *s = "GET /something HTTP/1.1\r\n";
printf("sscanf: %d\n", sscanf(s, "GET %s HTTP", a));
printf("a: %s\n", a);
printf("sscan: %d\n", sscanf("GET /more HTTP/1.1\r\n", "GET %s HTTP", a));
printf("a: %s\n", a);
}
I get the correct output:
sscanf: 1
a: /something
sscan: 1
a: /more
But when I comment out the lines between empty comments, I get:
sscan: 0
a: (null)
Question 1 : How can this be?
And a little more: if I write char *a = NULL, I get:
sscanf: 0
a: (null)
sscan: 0
a: (null)
Question 2 : Why?
source
share