ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am using C++BuilderX and am facing some problems while working with files.
My understanding was that fwrite() moves the pointer when writing something in a file.
Code:
char person[30];
char read_person[30];
FILE *fp;
fp = fopen("myfile.dat","wb+");
...(I read something in string person from stdin)
fwrite(&person,sizeof(person),1,fp);
fread(&read_person,sizeof(read_person),1,fp);
fclose(fp);
Don't I need to go back to the beginning of string, i.e. with fseek(),in file befor I can read it with fread()?
Any idea or hint is why fread() is reading the string I entered in file withoug use of fseek()?
In order to cut short the code for forum questions, I did not mention that person is a struct.
Actually, sizeof() works fine with struct. Maybe fread() and fwrite() can't?? I also tried without the & sign but to no avail.
Definition of fread() and fwrite() suggests buffer could be anything:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.