i am reading a line from a file with fgets. then trying to parse that line with sscanf to place in 2 vars. but that is not working as i expect. take the following line as a line read from the file(unix format):
now assuming the file has been opened correctly, which it has, the following code:
Code:
char buffer[255];
char name[255];
int int_var;
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
printf("line read failed\n");
fclose(fp);
return;
} else {
sscanf(buffer, "%s=%d", &name, &int_var);
printf("%s\n", name);
printf("%d\n", int_var);
}
prints out name to equal "test=40", which is the whole line that was read. and int_var is equal to nothing. i replaced the "=" with a space " " in both code and the file(test 40). and that was parsed fine. just doesn't work with the "=" sign between the string and integer. odd to me. perhaps not to the rest of you. any idea why the "=" doesn't work for me here? thanx.