G
Giff
Hello,
I have spent about one hour like an idiot on this stupid piece of code:
int main(int argc, char *argv[])
{
int a;
float b;
string c;
int res = sscanf( "20 10.0 hello", "%d %f %s", &a, &b, &c);
printf("%d %f\n", a, b); //fine
printf("%s", c); //->segfault
return 0;
}
As the comment says, it segfaults at the second printf.
I suppose I can't assign to a string using sscanf? Thing is that I
thought I saw it done like that somewhere on the net...
What puzzles me most is: why does it crash only when I try to print the
string?
How would you do it without having to resort to char arrays?
Thanks,
G
I have spent about one hour like an idiot on this stupid piece of code:
int main(int argc, char *argv[])
{
int a;
float b;
string c;
int res = sscanf( "20 10.0 hello", "%d %f %s", &a, &b, &c);
printf("%d %f\n", a, b); //fine
printf("%s", c); //->segfault
return 0;
}
As the comment says, it segfaults at the second printf.
I suppose I can't assign to a string using sscanf? Thing is that I
thought I saw it done like that somewhere on the net...
What puzzles me most is: why does it crash only when I try to print the
string?
How would you do it without having to resort to char arrays?
Thanks,
G