reading random file

This is a discussion on reading random file within the C Programming forums, part of the General Programming Boards category; hi, i currently doing a program that can read from output file that i had created.Here is my problem : ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    36

    reading random file

    hi, i currently doing a program that can read from output file that i had created.Here is my problem : how do i read in randomly into struct
    by the way i am using fread because i wanna read a binary file..and i don't know how to continue it..can i hav any tips..Thanks
    Below are only part of the code..
    Code:
    typedef struct abc {
    
    char a[10];
    char b[20];
    char c[30];
    
    } Data;
    
    etc...
    
    Data *entry;
    time_t t1;
    
    /* let say i got a 100 data in the file and i wanna read only 10 randomly of it.. */
    
    for (j=0; j<10 ; j++)
    {
         
              srand48((long) tl); /* tl is a some time variable cos i need to calculate the timing too */
              fseek(infile, 0, SEEK_SET);
              random_number = lrand48()%1500000;
    
                if (fread(entry, sizeof(Data), 1, infile)) {
                    
                /* i dunno what to do in here */
                    
                /* issit correct if i do like this */
                    fread(entry->a, sizeof(entry->a), 1, infile);
                    .......
    
                 }
           printf("%s,%s,%s\n",entry->a, entry->b, entry->c); 
           fseek(infile, 3 , SEEK_CUR);
        }

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    randomly
    And what does *that* mean?


    Also please note that we're not auto-homework-solver bots.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    Quote Originally Posted by jafet
    And what does *that* mean?


    Also please note that we're not auto-homework-solver bots.
    I am not asking u to give me a solution..i jus asking how to solve it..like tips..cos i stuck all the half way..by the way..thanks for reading my post..

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    thanks..anyway..i solved it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading random line from a text file
    By helloamuro in forum C Programming
    Replies: 24
    Last Post: 05-03-2008, 10:57 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21