Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ read text file until specific delimiter
    primarykey
    data
    text
    <p>Okay, so i have a huge file which i want to read in 1 Chapter at a time. a chapter is delimited by <code>'$'</code>. I am not really familiar with C++ just yet, so i made something that would read in a chapter as i would expect it to in C/C++.</p> <pre><code>#include &lt;nds.h&gt; #include &lt;stdio.h&gt; #include &lt;string&gt; #include &lt;vector&gt; #include &lt;sstream&gt; int dataFileLoc = 7; std::string fileReader(){ FILE * dataFile; std::string chapterBuffer = ""; const int buffersize = 1024; char charBuffer[buffersize]; bool foundEnd = false; dataFile = fopen("xc3_.tsc", "rt");//open data file fseek(dataFile,dataFileLoc,SEEK_SET); while(!foundEnd){ fread(charBuffer,1,buffersize,dataFile); for(int i=1; i&lt;buffersize; i++){ if(charBuffer[i] == '$'){ foundEnd = true; charBuffer[i] = '\0'; dataFileLoc = ftell(dataFile)-(buffersize-i); break;//break to spare some time } } chapterBuffer.append(charBuffer); } fclose(dataFile);//done with the file for now. checkerTemp(chapterBuffer); return chapterBuffer; } </code></pre> <p>The result should be fine. I have never reached end of file yet. so it might fail there. However, it seems to seemingly random (consistent, but at seemingly random locations). The fail would result in an injection of junk data in the string (like 8 chars worth), followed by normal data again.</p> <p>Does anyone have an idea what could cause this, or does anyone have a proper more C++ way to do this? Something with a string reader?</p> <p>Thanks in advance,</p> <p>-Smileynator</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload