Guest User

Untitled

a guest
Jan 22nd, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. // Zad 1 :
  2.  
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6.  
  7. #define BUFSIZE 20
  8.  
  9. int main(int argc, char **argv)
  10. {
  11. if(argc < 3)
  12. return (-1);
  13.  
  14.  
  15. char bufor[BUFSIZE];
  16.  
  17. int n;
  18.  
  19. int pierwszy = open(argv[1], O_RDONLY);
  20. int drugi = open(argv[2], O_WRONLY);
  21.  
  22. while((n = read(pierwszy, bufor, BUFSIZE)) > 0)
  23. {
  24. write(drugi, bufor, n);
  25. }
  26.  
  27. close(pierwszy);
  28. close(drugi);
  29.  
  30. return 0;
  31. }
  32.  
  33. /// Zad 2 :
  34.  
  35. #include <sys/types.h>
  36. #include <sys/stat.h>
  37. #include <fcntl.h>
  38. #include <unistd.h>
  39. #include <memory.h>
  40.  
  41. int main(int argc, char **argv)
  42. {
  43. if(argc < 3)
  44. return (-1);
  45.  
  46. char bufor;
  47. char text[100][100];
  48. memset(text, '\0', 100*100);
  49.  
  50.  
  51. int n;
  52.  
  53. int pierwszy = open(argv[1], O_RDONLY);
  54. int drugi = open(argv[2], O_WRONLY);
  55.  
  56. int IloscNowychLinni=0;
  57. {
  58. while((n = read(pierwszy, &bufor, 1)) > 0)
  59. {
  60.  
  61. if(bufor=='\n'){
  62. IloscNowychLinni++;
  63. continue;
  64. }
  65.  
  66. }
  67. }
  68.  
  69.  
  70. {
  71. int i=0;
  72. int j=0;
  73.  
  74. lseek(pierwszy,0,SEEK_SET);
  75.  
  76. while((n = read(pierwszy, &bufor, 1)) > 0)
  77. {
  78.  
  79. if(bufor=='\n'){
  80. i=i+1;
  81. j=0;
  82. continue;
  83. }
  84.  
  85. j=j+1;
  86. text[i][j]=bufor;
  87. }
  88. }
  89.  
  90.  
  91. {
  92. int i,j,k;
  93. for(i=0;i<IloscNowychLinni;i++){
  94. k=0;
  95. for(j=0;j<100;j++){
  96.  
  97. if(text[i][100-j]=='\0'){
  98. continue;
  99. }
  100. bufor=text[i][100-j];
  101. write(drugi,&bufor,1);
  102. }
  103. bufor='\n';
  104. write(drugi,&bufor,1);
  105. }
  106. }
  107.  
  108.  
  109. close(pierwszy);
  110. close(drugi);
  111.  
  112. return 0;
  113. }
  114.  
  115.  
  116. // zad 3 :
  117.  
  118.  
  119. #include <sys/types.h>
  120. #include <sys/stat.h>
  121. #include <fcntl.h>
  122. #include <unistd.h>
  123. #include <stdio.h>
  124. #include <memory.h>
  125.  
  126. int main(int argc, char **argv)
  127. {
  128. if(argc < 2)
  129. return (-1);
  130.  
  131. char bufor;
  132. int n;
  133.  
  134. int pierwszy = open(argv[1], O_RDONLY);
  135.  
  136.  
  137. int max=0;
  138. int temp=0;
  139.  
  140. while((n = read(pierwszy, &bufor, 1)) > 0)
  141. {
  142. if(bufor=='\n'){
  143.  
  144. if(temp>max)
  145. {
  146. max=temp;
  147. }
  148. temp=0;
  149. }
  150. temp++;
  151. }
  152.  
  153. close(pierwszy);
  154.  
  155. printf("Najwieksza liczba liter w zdaniu to : %d \n", max);
  156.  
  157.  
  158. return 0;
  159. }
  160.  
  161. /// zad 4:
  162.  
  163.  
  164. #include <sys/types.h>
  165. #include <sys/stat.h>
  166. #include <fcntl.h>
  167. #include <unistd.h>
  168. #include <stdio.h>
  169. #include <memory.h>
  170.  
  171. int main(int argc, char **argv)
  172. {
  173.  
  174. int RozmiarPlikow=0;
  175. int i;
  176. int n;
  177. int bufor;
  178.  
  179. for(i=1;i<argc;i++){
  180.  
  181. int plik = open(argv[1], O_RDONLY);
  182.  
  183. while((n = read(plik, &bufor, 1)) > 0)
  184. {
  185. RozmiarPlikow++;
  186. }
  187. close(plik);
  188. }
  189.  
  190.  
  191.  
  192. printf("Wspolny rozmiar plikow to : %d \n", RozmiarPlikow);
  193.  
  194. return 0;
  195. }
Add Comment
Please, Sign In to add comment