The scan specification is not %s[whatever] , it's just %[whatever] , so your format string should look more like: "%d\nLen %d\nExpire %d\n\n%[^\0]" .
As a side note, scanf and the other side consider that any empty space in the format string is equivalent to any other space - any spaces in the format correspond to an arbitrary sequence of space characters at the input (and a new line is considered a space). Your current format string is well documenting the format you expect, but in terms of what it really matches, you can change it to something like: "%d Len %d Expire %d %[^\0]" without affecting what he will do. In particular, your two consecutive newlines are not really up to the mark.
Edit: thinking about this, [\0] causes only a small problem: "\ 0" ends the line, so you get an invalid specification for scanning. Since you just want the rest of the input to risorsa to risorsa , it might be easiest to use %c : "%d Len %d Expire %d %4999c" .
And yes, this time I really tested it:
#include <stdio.h> char *riposta = "200\n" "Len 1040\nExpire 30\n" "\n1111111111111111111111111\n" "1111111111111111111111111\n" "1111111111111111111111111\n"; typedef struct Server_risp { int type; int expire; int len; int sup; int inf; char risorsa[5000]; }Server_risp; int main() { Server_risp risp; sscanf(riposta, "%d Len %d Expire %d %4999c", &risp.type, &risp.len, &risp.expire, risp.risorsa); printf("%s\n", risp.risorsa); }
result:
1111111111111111111111111 1111111111111111111111111 1111111111111111111111111
Edit 2: I'm not sure exactly what the problem you're working with. I modified it a bit to show both the leading and the built-in white space:
#include <stdio.h> char *riposta = "200\n" "Len 1040\nExpire 30\n" "| |" "\n1111111111111111111111111\n" "1111111111111111111111111\n" "1111111111111111111111111\n"; typedef struct Server_risp { int type; int expire; int len; int sup; int inf; char risorsa[5000]; }Server_risp; int main() { Server_risp risp; sscanf(riposta, "%d Len %d Expire %d%4999c", &risp.type, &risp.len, &risp.expire, risp.risorsa); printf("%s\n", risp.risorsa); }
... and got pretty much the expected result:
| | 1111111111111111111111111 1111111111111111111111111 1111111111111111111111111