|
-
May 20th, 2004, 01:49 AM
#1
File Streams
Hi All,
i am having this problem (and i looked in many places and cant find anything useful) in ANSI C the function called "fseek" it is used as;
int fseek(FILE *stream,long int offset,int orgin); i dont know how to use the interger "offset"
please exlpain
Bill
-
May 20th, 2004, 03:48 AM
#2
-
May 20th, 2004, 05:03 AM
#3
fseek is used to "move" the file handle, which as u probably now is not a single pointer, and so u can't "move" it like other pointers (ptr++).
1st arg: is the file pointer
2nd & 3rd arguments are integers which are used to specify where will the pointer move to. The 3rd arg is the initial position (look at msdn for more details) of the pointer and the 2nd arg is HOW MANY BYTES will the pointer move from the initial position.
example 1:
fseek(fp,100,SEEK_SET) moves the fp poiner at the 100th byte of the file.
fseek (fp,0,SEEK_END) moves fp at the end of the file.
-
May 20th, 2004, 08:23 PM
#4
Thanks but why is 0 the end of the file and if i use one does it put the EOF to the first byte?!?!?
-
May 21st, 2004, 01:56 AM
#5
Ok...
fseek (File pointer name, Size of the record, From where)
(1st arg) (2nd arg) (3rd arg)
1st arg : It's ur file pointer name ex : fp
2nd arg : It is the sizeof the record ex :
Assume that u have a structure
struct emp
{
int empno;
char ename[20];
float sal;
}e;
The size of the struct emp e variable is 2+20+4 = 26 bytes.
While specifying the sizeof the record u have to specify the sign also i.e -26 or + 26.
ok why and how ???
This depends on the 3rd argument i.e
a) SEEK_SET : means from the begining of the file. Always u can move to front only, means u have give +26.
b) SEEK_CUR : means from the current position of the file. U can move either front or back, means u can give +26 or -26 according to u requirement.
c) SEEK_END : means from the the end of the file. Always u can move to backwards only, means u have to give -26.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|