Thread: filepointer

  1. #1
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90

    filepointer

    hi

    i work with text-files that i opened with fopen. i can get and restor the curent psoition by using fgetpos and fsetpos. but is it also possible to just move the pointer one element backward or forwar by simply incrementing the handle or something similar? always storing and setiting the position isn't too efficient i think. is it also possible to jump to a known position (for example i know that i just have to start with the 1000 st char) without just looping and reading char after char till 100 is reached?

    thanks

  2. #2
    Registered User The Junglist's Avatar
    Join Date
    Nov 2002
    Posts
    42
    fseek() is what you are looking for.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use this:
    Code:
    fseek(MyFile, 1, SEEK_CUR);
    to go one step forward and this:
    Code:
    fseek(MyFile, -1, SEEK_CUR);
    to go one step backwards. Of course you can change 1 to some other value (constant or variable) if you want to move more than one step. Make sure you catch the return value to make sure no error occured, ie you move outside the bounds.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    Re: filepointer

    Originally posted by stormbringer
    hi

    i work with text-files that i opened with fopen. i can get and restor the curent psoition by using fgetpos and fsetpos. but is it also possible to just move the pointer one element backward or forwar by simply incrementing the handle or something similar? always storing and setiting the position isn't too efficient i think. is it also possible to jump to a known position (for example i know that i just have to start with the 1000 st char) without just looping and reading char after char till 100 is reached?

    thanks
    fseek () as had been already mentioned. incrementing the FILE pointer will do everything but what you want it to; it points to a struct that contains information about the file in question, and does not point to the data in the file at all.
    hello, internet!

  5. #5
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90
    thanks everybody

    is there any document where i can see how the struct for tehe filepointer looks. i'm just interested, of course i'll use fseek.

  6. #6
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90
    that's something that makes me curious since a long time. the c standard is very simple, so the stuff like reading from strams and so on is provided by the compiler's .h files.
    1. the .h files just have definitions and so on. the source that actualy does something has to be in a .c file, doesn't it. so how does the compiler know where that .c file is and how the name is. there ain't something like a "note" in the .h file.

    2. are the routines that do stuff like opening io ports, sockets and so on writen in c or assembly or what? that would mean that they are very platform dependend. so the only thing making code portable ist, that for every platfor exist's a speciel compiler with special standard .h files.

    this all get's me a little bit confused.

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    4
    The C Runtime is the gate to platform independence. The Runtime itself calls for the specific OS routines (so you have the same programming interface on every platform). The Filepointer is an handle, which the OS needs to perform file operations (yes, there's a structure the OS has, but you can't modify it directly. Instead you modify it by using the OS specific file operation functions)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. n00b question.... dat file related
    By hobbes67 in forum C Programming
    Replies: 7
    Last Post: 06-24-2005, 11:39 AM
  2. Filepointer
    By newguy27 in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2002, 04:37 AM
  3. how to get the output of a non-stop process?
    By dkt in forum C Programming
    Replies: 1
    Last Post: 04-27-2002, 11:18 AM
  4. Files
    By {Dnw} in forum C Programming
    Replies: 10
    Last Post: 08-27-2001, 07:37 AM