not to read the data from buffer line by line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chaitra N
    New Member
    • Apr 2011
    • 2

    not to read the data from buffer line by line

    I'm reading strings one after another and trying to split it using strtok_r. This doesnot seem to be working Is there any way around this?

    I have a .gz file from which I'm reading the data into the buffer in chunks.

    The below code works fine only for the first chunk on data. Later it just breaks out.
    Can any1 helpme with this?
    Code:
    while(1)
    {
    char buffer[SIZE];
            int bytes_read = gzread (f, buffer, SIZE - 1);
     buffer[bytes_read] = '\0';
    line = strtok_r(strdup(buffer), "\n", &next_line);
    while(line)
            {
          line  = strtok_r(NULL, "\n", &next_line);
            cout << line << endl;
       }
    if (bytes_read < SIZE - 1)
    {
    break;
    }
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Can you not just unpack the .gz archive into text files and use cin.getline to read your strings?

    Comment

    • Chaitra N
      New Member
      • Apr 2011
      • 2

      #3
      The file is pretty huge and unpacking it will take too much disk space.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        How much space would that be?

        Otherwise, you will have to write .gz decompressor.

        Comment

        Working...