Note that there are some explanatory texts on larger screens.

plurals
  1. POfgetc not starting at beginning of file - c
    primarykey
    data
    text
    <p>Problem solved here: <a href="https://stackoverflow.com/questions/20341044/fgetc-not-starting-at-beginning-of-large-txt-file">fgetc not starting at beginning of large txt file</a></p> <p>I am working in c and fgetc isn't getting chars from the beginning of the file. It seems to be starting somewhere randomly within the file after a <code>\n</code>. The goal of this function is to modify the array productsPrinted. If "More Data Needed" or "Hidden non listed" is encountered, the position in the array, productsPrinted[newLineCount], will be changed to 0. Any help is appreciated. </p> <p>Update: It works on smaller files, but doesn't start at the beginning of the larger,617kb, file.</p> <p>function calls up to category:</p> <pre><code>findNoPics(image, productsPrinted); findVisible(visible, productsPrinted); removeCategories(category, productsPrinted); </code></pre> <p>example input from fgetc():</p> <pre><code>Category\n Diagnostic &amp; Testing /Scan Tools\n Diagnostic &amp; Testing /Scan Tools\n Hidden non listed\n Diagnostic &amp; Testing /Scan Tools\n Diagnostic &amp; Testing /Scan Tools\n Hand Tools/Open Stock\n Hand Tools/Sockets and Drive Sets\n More Data Needed\n Hand Tools/Open Stock\n Hand Tools/Open Stock\n Hand Tools/Open Stock\n Shop Supplies &amp; Equip/Tool Storage\n Hidden non listed\n Shop Supplies &amp; Equip/Heaters\n </code></pre> <p>Code:</p> <p>void removeCategories(FILE *category, int *prodPrinted){</p> <pre><code>char more[17] = { '\0' }, hidden[18] = { '\0' }; int newLineCount = 0, i, ch = 'a', fix = 0; while ((ch = fgetc(category)) != EOF){ //if fgetc is outside while, it works// more[15] = hidden[16] = ch; printf("%c", ch); /*shift char in each list &lt;- one*/ for (i = 0; i &lt; 17; i++){ if (i &lt; 17){ hidden[i] = hidden[i + 1]; } if (i &lt; 16){ more[i] = more[i + 1]; } } if (strcmp(more, "More Data Needed") == 0 || strcmp(hidden, "Hidden non listed") == 0){ prodPrinted[newLineCount] = 0; /*printf("%c", more[0]);*/ } if (ch == '\n'){ newLineCount++; } } </code></pre> <p>}</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.
 

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