arrays of structures

Hi, I'm a beginner when it comes console C coding and have question about this. I think I must be forgetting something completely stupid or miss using sscanf or fprintf

My structure is:

typedef struct
{
char name[64];
unsigned long int location;
unsigned long int size;
} function_struct;

in main I declare an array like this:

function_struct f_info[28];

I read values from a file like this:

for( i = 0 ; i < 28 ; i++)
{
fgets (string_tmp, 200, pFile[0]);
sscanf(string_tmp, "%s, %x, %x, %*x, %*x", f_info[i].name,
f_info[i].location,
f_info[i].size);
}

and print them like this:

for(i = 0 ; i < 28 ; i++)
{
fprintf(pFile[1],"%-35s %-8x %x\n", f_info[i].name,
f_info[i].location,
f_info[i].size);
}

The problem is that the location and size come out very wrong.

THANKS ALL

Why are you scanning in more variables than your assigning?

Edit: Why are you scanning in 2 variables but ignoring them after the ones your assigning?

When you scanf, are you doing a printf() to verify it's being scanned correctly?
Last edited on
He is scanning exactly as many variables as he is assigning, isn't he?
But maybe you can try to write %[^,] instead of %s.
What does the file your trying to read look like? Explain in detail what your trying to do with the file.
Topic archived. No new replies allowed.