Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <pthread.h>
- #include <stdlib.h>
- using namespace std;
- const int x=1024;
- char tekst[x];
- void wpisaniePierwsze()
- {
- string const nazwaPliku("/home/student/Pulpit/plik1.txt");
- ofstream strumyk(nazwaPliku.c_str());
- cout << "Podaj tekst ktory chcesz zapisac w pierwszym pliku " << endl;
- cin.getline(tekst, x);
- if(strumyk)
- {
- strumyk << tekst << endl;
- }
- else
- {
- cout << "Blad przy otwieraniu pliku" << endl;
- }
- }
- void wpisanieDrugie()
- {
- string const nazwaPliku("/home/student/Pulpit/plik2.txt");
- ofstream strumyk(nazwaPliku.c_str());
- cout << "Podaj tekst ktory chcesz zapisac w drugim pliku " << endl;
- cin.getline(tekst, x);
- if(strumyk)
- {
- strumyk << tekst << endl;
- }
- else
- {
- cout << "Blad podczas otwierania pliku." << endl;
- }
- }
- void *pierwszy(void *arg){
- string const nazwaPliku("/home/student/Pulpit/uno.txt");
- ifstream strumyk(nazwaPliku.c_str());
- char y;
- int x=rand()%90+10;
- cout << "Przystepuje do wypisania tekstu z pliku :D" << endl;
- while(strumyk.get(y))
- {
- cout << y << endl;
- usleep(x);
- }
- cout << endl;
- cout << "Pierwszy wyraz wypisany, czas na drugi" << endl;
- pthread_exit(NULL);
- }
- void *drugi(void *arg){
- string const nazwaPliku("/home/student/Pulpit/dues.txt");
- ifstream strumyk(nazwaPliku.c_str());
- char c;
- int x=rand()%90+10;
- cout << "Zawartosc drugiego pliku: " << endl;
- while(strumyk.get(c))
- {
- cout << c << endl;
- usleep(x);
- }
- cout << endl;
- cout << "Koniec" << endl;
- pthread_exit(NULL);
- }
- int main()
- {
- pthread_t nun;
- pthread_t nuno;
- wpisaniePierwsze();
- wpisanieDrugie();
- pthread_create(&nun, NULL, &pierwszy, NULL);
- pthread_join(nun, NULL);
- pthread_create(&nuno, NULL, &drugi, NULL);
- pthread_join(nuno, NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement