Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. node *fileToList(const char *name, int *count ) //ïðåîáðàçîâàíèå ôàéëà â ñïèñîê, ïîäñ÷åò êîë-âà ýëëåìåíòîâ ñïèñêà
  2. {
  3. //îòêðûòåå ôàéëà
  4. ifstream file(name);
  5. if (file == 0)
  6. {
  7. cout<<"file can`t be opened"<<endl;
  8. file.close();
  9. return NULL;
  10. }
  11.  
  12. //ñîçäàíèå êîëüöåâîãî ñïèñêà
  13.  
  14. //ïåðâûé ýëëåìåíò
  15.  
  16. node *tail; // ñîçäàåì ññûëêó íà áóäóùèé õâîñò
  17.  
  18. char buf[100];
  19. file.get(buf, 99);
  20. if (file.eof()) // åñëè ôàéë íå ïóñò, òîãäà ñîçäàåì êîëüöåâîé ñïèñîê
  21. {
  22. cout<<"file is empty"<<endl;
  23. file.close();
  24. return NULL;
  25. }
  26. file.ignore();
  27. tail = addFirst(buf);
  28.  
  29. //ïîñëåäóþùèå
  30. *count = 1;
  31.  
  32.  
  33. while (!file.eof())
  34. {
  35. prnList(tail);
  36. cout<<endl;
  37.  
  38.  
  39. file.ignore();
  40. file.get(buf, 99);
  41. tail = addTail(tail, buf);
  42. (*count)++;
  43.  
  44. }
  45.  
  46. prnList(tail);
  47.  
  48. //çàâåðøåíèå ðàáîòû
  49. file.close();
  50. return tail;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement