-3

So lets say I have a text file of strings. Lets say I read half of the text file into an array of strings or some kind of buffer. And then I do some operations on that array. Then lets say a want to go back to my text file and start reading the text file from where I left off. How would I do that? How do I tell the program to start off where I last stopped reading in a text file. I do not need the code necessarily but rather the process/logic. Thanks.

shmosel
  • 49,289
  • 6
  • 73
  • 138
Vise
  • 3
  • 1
  • 1
    Don't tag spam. – shmosel Mar 22 '18 at 04:34
  • 2
    What have you tried and what are you having trouble with. Once you start coding this the answer should become reasonably obvious. "How do I tell the program to start off where I last stopped reading in a text file." => just keep the handle to the file and it will do this without having to tell it anything. – Peter Lawrey Mar 22 '18 at 04:35
  • Possible duplicate of [How do I read from a specific line in a file?](https://stackoverflow.com/questions/27789863/how-do-i-read-from-a-specific-line-in-a-file) – Mohamed Chaawa Mar 22 '18 at 04:36

1 Answers1

-1

This is what im using to read my file, usually i keep a counter to read until where i am now (The Current Position of my reading)

void readData(){
        FILE *f=fopen ("db.txt","r");
        if(!f)
        {
            printf("File Not Found\n");
        }
        else
        {
            while(!feof(f))
            {
                fscanf(f,"%[^#]#%d\n",&test1[counter].name,&test1[counter].level);
                counter++;
            }
        fclose(f);
        }
    }

My Point is keep a counter of where your last reading is and then continue from the last counter you are on. Hope this helps. Cheers!

Karen
  • 122
  • 11
  • 2
    I strongly recommend reading [Why is “while ( !feof (file) )” always wrong?](https://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong) And since this question is tagged C++, I recommend giving Kate Gregory's [Stop Teaching C](https://www.youtube.com/watch?v=YnWhqhNdYyk) presentation a watch. – user4581301 Mar 22 '18 at 05:15