#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    3
    Rep Power
    0

    extremely easy... string function


    I just need to loop through a long string to analyze it.

    I read a file into char massive;
    then I need to:

    read 41 bytes,,, trash them
    read 3 bytes compare them
    read until end of line
    loop until end of the variable.

    whats the string function I need
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,151
    Rep Power
    2222
    So basically you want to read in a line and pull out characters 41,42, and 43.
    Code:
    #define MASSIVE_SIZE 1024  // or whatever massive means here
    char massive[MASSIVE_SIZE];
    
    // code placed in a function to emphasize that massive probably does not belong on the stack.
    void foo(FILE *fp)
    {
        char substring[4];
    
        fgets(massive,MASSIVE_SIZE,fp);
        strncpy(substring,&massive[41],3);
        substring[3] = '\0';   // need to manually add the null-terminator
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    3
    Rep Power
    0

    massive


    I was reading 41 characters, reading 3 characters comparing and updating a counter then reading to /n
    with this method I was doing many reads in the loop.
    now I would like to read the whole file 21000000 bytes (massive) into a variable and then loop through it as above.. each line has 41 characters of junk 3 lines of info and the rest junk.

IMN logo majestic logo threadwatch logo seochat tools logo