fscanf problem

J

jespersh

I have a problem concerning fscanf: I which to save an array of
structures to a file, and to boil things down let's say I save the
'type' member (which is a char) as:

void save(struct part *ptr, const char *file, int npart){
FILE *fout;
int n;

fout = fopen(file, "w");
/* some check */

for ( n=0; n<npart; n++ )
fprintf(fout, "%c\n", ptr[n].type);

fclose(fout);
}

(Here the array is 'npart' long.) Now, I wish to load the data through
the following function:

void load(struct part *ptr, const char *file, int npart){
FILE *fin;
int n;

fin = fopen(file, "r");
/* some check */

for ( n=0; n<npart; n++ )
fscanf(fin, "%c", &ptr[n].type);

fclose(fin);
}

This will lead to very strange behavior. As I understand fscanf skips
\n, space etc, but it seems from the output as if it includes the
newline character twice.

Am I missing the definition of fscanf?

Jesper
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fscanf 31
error: invalid use of void expression 15
parser 2
A seg fault 11
Adding adressing of IPv6 to program 1
detabbing again 105
URGENT 1
fscanf problem 5

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top