Note that there are some explanatory texts on larger screens.

plurals
  1. POWhile loop for loading files not working
    text
    copied!<p>I'm trying to make a linked list that adds emails from a text file in the order they were received. The while loop, that I'm using to retrieve email info and make new nodes, is not even completing a single iteration (I tested it with an integer and another condition for stopping). My .txt file worked when loading it with someone else's program, so I believe my source_file.get aren't working?</p> <pre><code>int Classify::Load_email(char filename[]) { ifstream source_file(filename); char eof_prime; if(!source_file) // Checks whether there is anything in the file return 0; if(!email_head) { // If there is no head, creates a new node for it to point to, and have tail point to it as well email_head = new email_node; email_tail = email_head; email_tail-&gt;next = NULL; } source_file &gt;&gt; eof_prime; // Primes the eof function. while(!(source_file.eof())); { source_file.get(email_tail-&gt;email_data.sent, 50, '|'); source_file.get(email_tail-&gt;email_data.from, 50, '|'); source_file.get(email_tail-&gt;email_data.to, 50, '|'); source_file.get(email_tail-&gt;email_data.subject, 100, '|'); source_file.get(email_tail-&gt;email_data.contents, 200, '|'); // If source_file isn't eof, then create a new node, connect the nodes, then have tail point to it, make next NULL if(!(source_file.eof())) { email_tail-&gt;next = new email_node; // retaining the order emails were sent in, so always adding to the end email_tail = email_tail-&gt;next; email_tail-&gt;next = NULL; } } // end while loop return 1; }; </code></pre>
 

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