Hello. There is a task to read integer numbers from a file and add to the end of a single-linked linear list. I implement reading:
void createListFromFile(List &start) { ifstream f("f.txt"); deleteList(start); List p = new Node; start = p; while(!f.eof()){ f >> p->inf; p->next = new Node; p = p->next; } p->next = NULL; f.close(); }
I realize the seal:
void printList(List start) { if (!start) cout << endl << "Список пуст!"; else while (start) { cout << start->inf << "\t"; start = start->next; } cout << endl; }
As a result, if there are n numbers in the file, then n + 1 is printed on the screen and is necessarily left, for example -842150451. It's clear that he either reads one extra empty number and assigns it an empty (random) value or prints an extra one. But I can not find a mistake. I ask for your help. Thank.