Thursday, 15 May 2014

pointers - C sscanf: why is this segfaulting? -



pointers - C sscanf: why is this segfaulting? -

i'm trying take tokens in format of "%i / %i%s" , split them 3 variables.

char char1[20]; int int1; int int2; sscanf(token, "%[^/]/%d", char1, &int2); printf("%s - %i ", char1, &int2);

it segfaults. doing wrong?

i've tried changing %d %i, no difference.

you shouldn't print address of int2 in printf. working me:

const char *token = "qwerasdf/10"; char char1[20]; int int2; sscanf(token, "%[^/]/%d", char1, &int2); printf("%s - %i ", char1, int2);

output:

qwerasdf - 10

c pointers sscanf

No comments:

Post a Comment