I want to read a the last record in my structure. I don't know how to do this (I think you use SEEK_END but I can't work out how to use it) so can some please help me out
I want to read a the last record in my structure. I don't know how to do this (I think you use SEEK_END but I can't work out how to use it) so can some please help me out
OS:- XP
Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)
You need to know what form that last entry will be...a long, a byte another struct!!!
I don't quite understand what you mean. But this is my sturc
Is that any helpCode:struct data { char fname [51],sname [51],tel[15]; int x; }a;
OS:- XP
Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)
Ok...well assuming you mean that the int is the last record, you could address it as
IE;Code:a.x
Code:a.x = 10;
Can someone give me an example of using SEEk_END
Thank you
OS:- XP
Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)
According to my book seek end is just a condition used with fseek.
You have either SEEK_SET,SEEK_CUR and SEEK_END. Which have meanings of "seek from start of file", "seek from current location" and "seek from end of file" respectivly.
int fseek (FILE *stream, long int offset, int origin);
origin must be one of the above three.
http://uk.geocities.com/ca_chorltonkids
I presume you mean you have a file that you wrote with fwrite, and contains a load of structs. Now you want to get the last one in the file back into memory with fread(), right?
If so, fopen() the file, then fseek() to the correct position something like
>fseek(fp, sizeof(struct whatever) * -1, SEEK_END);
then perform the read. This fseek simply seeks a certain amount of bytes backwards from the end of the file.
Does this help?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]