Advertisement
Guest User

Untitled

a guest
May 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <sstream>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. struct element
  10. {
  11. string slowo;
  12. element *next;
  13. };
  14. void zadanie1(string &wiadomosc);
  15.  
  16. int main()
  17. {
  18. string wiadomosc="";
  19.  
  20. cout<<"Zadanie 1: "<<endl;
  21. cout<<endl;
  22. zadanie1(wiadomosc);
  23. cout<<"------------------------------------------";
  24. cout<<endl;
  25.  
  26. return 0;
  27. }
  28. void zadanie1(string &wiadomosc)
  29. {
  30. string sciezka;
  31. string bufor="", znak;
  32. ifstream plik;
  33. element *stos = nullptr;
  34. bool koniec;
  35. sciezka="dane.txt";
  36. plik.open(sciezka);
  37.  
  38. while(!plik.eof())
  39. {
  40.  
  41. koniec=0;
  42. while(!koniec && !plik.eof())
  43. {
  44. getline(plik, bufor, ' ');
  45.  
  46.  
  47. if(bufor.back() =='.' || bufor.back() =='!' || bufor.back() =='?')//sprawdzanie ostatniego znaku stringa
  48. {
  49. znak=bufor.back();
  50. koniec=1;
  51. bufor.pop_back();
  52. }
  53. bufor=bufor + " ";
  54. element *el= new element;
  55. el -> slowo = bufor;
  56. el -> next = stos;
  57. stos = el;
  58.  
  59.  
  60.  
  61. //cout<<bufor<<endl;
  62. }
  63. while(stos!=nullptr)//usuwanie elementow ze stosu
  64. {
  65. bufor=stos -> slowo;
  66. element *temp=stos;
  67. stos=stos ->next;
  68. delete temp;
  69. wiadomosc=wiadomosc+bufor;
  70. }
  71. wiadomosc.pop_back();
  72. wiadomosc=wiadomosc+znak;
  73. wiadomosc=wiadomosc+"\n";
  74. znak="";
  75. }
  76. cout<<wiadomosc;
  77. cout<<endl;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement