Thread: fseek and storing ints

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    91

    fseek and storing ints

    how would you seek to a particular spot in a file and read an int?

    if i have a file full of ints
    50 51 9

    how do i read each of these ints using fseek?
    Code:
    int i = 0;
    int temp_Var;
    while( (seeker = fseek(inputfile, i * sizeof(int), SEEK_SET))!=0) {
    //store into a  temp variable? how to?
    
      i++;
    }

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Why would you read file using fseek at all. See FAQ on this
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >if i have a file full of ints
    >50 51 9
    If the ints in the file are ascii (readable with a text editor), you can't use fseek() to seek to a particular int. You would need to read each one using fscanf() until you reach the one in question.

    If the file is binary (unreadable except with a hex editor) then fseek() should work.
    Last edited by swoopy; 04-04-2005 at 01:59 PM.

  4. #4
    High Flyer stumpster123's Avatar
    Join Date
    Mar 2005
    Posts
    26
    Well fseek just moves around the file pointer you would still need to use fscanf or fread to read in the integer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Image Processing Help Required
    By dantu1985 in forum C Programming
    Replies: 7
    Last Post: 12-31-2007, 09:30 AM