2

error: incompatible type for argument 1 of ‘fwrite’ /usr/include/stdio.h:688: note: expected ‘const void * restrict’ but argument is of type ‘struct oseba’ make: *** [E1041080] Error 1

struct oseba{
char baza[100];
int telefonska;
char ime[10];
char priimek[20];
int dan;
int mesec;
int leto;

};

boys i need help! what is wrong?

---------------------------write-----------------------

FILE*file=fopen("fhfh.dat","wb");
if(file!=NULL)
{   fwrite(oseba1,sizeof(struct oseba),1,file);
    fclose(file);
}

1 Answer 1

6

You need to pass a pointer to the structure. That is,

fwrite(&oseba1, sizeof(struct oseba), 1, file);

However beware that by writing structs into a binary file, it is highly probable that the file thus saved will not be portable, e.g. you cannot share it even between 32-bit and 64-bit compilations of your program or from platform to another.

Sign up to request clarification or add additional context in comments.

3 Comments

The last sentence is irrelevant to the question and would be better as a comment.
@immibis: That last sentence is clearly separated from the main body of the answer by a <hr>. It's an important caveat that anyone attempting to read & write structs to a file should be aware of. So it deserves to be in the answer, not in a comment, since comments are "second-class citizens" on Stack Exchange site.
Well, it wasn't that much separated when immibis wrote that comment :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.