Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <cstdlib>
- using namespace std;
- struct element
- {
- string slowo;
- element *next;
- };
- void zadanie1(string &wiadomosc);
- int main()
- {
- string wiadomosc="";
- cout<<"Zadanie 1: "<<endl;
- cout<<endl;
- zadanie1(wiadomosc);
- cout<<"------------------------------------------";
- cout<<endl;
- return 0;
- }
- void zadanie1(string &wiadomosc)
- {
- string sciezka;
- string bufor="", znak;
- ifstream plik;
- element *stos = nullptr;
- bool koniec;
- sciezka="dane.txt";
- plik.open(sciezka);
- while(!plik.eof())
- {
- koniec=0;
- while(!koniec && !plik.eof())
- {
- getline(plik, bufor, ' ');
- if(bufor.back() =='.' || bufor.back() =='!' || bufor.back() =='?')//sprawdzanie ostatniego znaku stringa
- {
- znak=bufor.back();
- koniec=1;
- bufor.pop_back();
- }
- bufor=bufor + " ";
- element *el= new element;
- el -> slowo = bufor;
- el -> next = stos;
- stos = el;
- //cout<<bufor<<endl;
- }
- while(stos!=nullptr)//usuwanie elementow ze stosu
- {
- bufor=stos -> slowo;
- element *temp=stos;
- stos=stos ->next;
- delete temp;
- wiadomosc=wiadomosc+bufor;
- }
- wiadomosc.pop_back();
- wiadomosc=wiadomosc+znak;
- wiadomosc=wiadomosc+"\n";
- znak="";
- }
- cout<<wiadomosc;
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement