Advertisement
Guest User

Untitled

a guest
May 17th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <pthread.h>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9. const int x=1024;
  10. char tekst[x];
  11.  
  12. void wpisaniePierwsze()
  13. {
  14. string const nazwaPliku("/home/student/Pulpit/plik1.txt");
  15. ofstream strumyk(nazwaPliku.c_str());
  16. cout << "Podaj tekst ktory chcesz zapisac w pierwszym pliku " << endl;
  17. cin.getline(tekst, x);
  18.  
  19. if(strumyk)
  20. {
  21. strumyk << tekst << endl;
  22. }
  23. else
  24. {
  25. cout << "Blad przy otwieraniu pliku" << endl;
  26. }
  27. }
  28. void wpisanieDrugie()
  29. {
  30. string const nazwaPliku("/home/student/Pulpit/plik2.txt");
  31. ofstream strumyk(nazwaPliku.c_str());
  32. cout << "Podaj tekst ktory chcesz zapisac w drugim pliku " << endl;
  33. cin.getline(tekst, x);
  34.  
  35. if(strumyk)
  36. {
  37. strumyk << tekst << endl;
  38. }
  39. else
  40. {
  41. cout << "Blad podczas otwierania pliku." << endl;
  42. }
  43. }
  44.  
  45. void *pierwszy(void *arg){
  46.  
  47.  
  48.  
  49. string const nazwaPliku("/home/student/Pulpit/uno.txt");
  50. ifstream strumyk(nazwaPliku.c_str());
  51. char y;
  52. int x=rand()%90+10;
  53. cout << "Przystepuje do wypisania tekstu z pliku :D" << endl;
  54. while(strumyk.get(y))
  55. {
  56. cout << y << endl;
  57. usleep(x);
  58. }
  59. cout << endl;
  60. cout << "Pierwszy wyraz wypisany, czas na drugi" << endl;
  61. pthread_exit(NULL);
  62. }
  63.  
  64. void *drugi(void *arg){
  65.  
  66.  
  67. string const nazwaPliku("/home/student/Pulpit/dues.txt");
  68. ifstream strumyk(nazwaPliku.c_str());
  69. char c;
  70. int x=rand()%90+10;
  71. cout << "Zawartosc drugiego pliku: " << endl;
  72. while(strumyk.get(c))
  73. {
  74. cout << c << endl;
  75. usleep(x);
  76. }
  77. cout << endl;
  78. cout << "Koniec" << endl;
  79. pthread_exit(NULL);
  80.  
  81. }
  82. int main()
  83. {
  84. pthread_t nun;
  85. pthread_t nuno;
  86.  
  87. wpisaniePierwsze();
  88. wpisanieDrugie();
  89.  
  90.  
  91. pthread_create(&nun, NULL, &pierwszy, NULL);
  92. pthread_join(nun, NULL);
  93. pthread_create(&nuno, NULL, &drugi, NULL);
  94. pthread_join(nuno, NULL);
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement