Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- node *fileToList(const char *name, int *count ) //ïðåîáðàçîâàíèå ôàéëà â ñïèñîê, ïîäñ÷åò êîë-âà ýëëåìåíòîâ ñïèñêà
- {
- //îòêðûòåå ôàéëà
- ifstream file(name);
- if (file == 0)
- {
- cout<<"file can`t be opened"<<endl;
- file.close();
- return NULL;
- }
- //ñîçäàíèå êîëüöåâîãî ñïèñêà
- //ïåðâûé ýëëåìåíò
- node *tail; // ñîçäàåì ññûëêó íà áóäóùèé õâîñò
- char buf[100];
- file.get(buf, 99);
- if (file.eof()) // åñëè ôàéë íå ïóñò, òîãäà ñîçäàåì êîëüöåâîé ñïèñîê
- {
- cout<<"file is empty"<<endl;
- file.close();
- return NULL;
- }
- file.ignore();
- tail = addFirst(buf);
- //ïîñëåäóþùèå
- *count = 1;
- while (!file.eof())
- {
- prnList(tail);
- cout<<endl;
- file.ignore();
- file.get(buf, 99);
- tail = addTail(tail, buf);
- (*count)++;
- }
- prnList(tail);
- //çàâåðøåíèå ðàáîòû
- file.close();
- return tail;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement