daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest May 16th, 2018 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. zhela@FlawlessVictory ~ $ mkdir polina
  2. zhela@FlawlessVictory ~ $ cd polina/
  3. zhela@FlawlessVictory ~/polina $ mkdir a
  4. zhela@FlawlessVictory ~/polina $ mkdir b
  5. zhela@FlawlessVictory ~/polina $ mkdir c
  6. zhela@FlawlessVictory ~/polina $ cd b
  7. zhela@FlawlessVictory ~/polina/b $ mkdir bb
  8. zhela@FlawlessVictory ~/polina/b $ mkdir ba
  9. zhela@FlawlessVictory ~/polina/b $ cd ..
  10. zhela@FlawlessVictory ~/polina $ cd a
  11. zhela@FlawlessVictory ~/polina/a $ mkdir aa
  12. zhela@FlawlessVictory ~/polina/a $ mkdir ab
  13. zhela@FlawlessVictory ~/polina/a $ cd aa
  14. zhela@FlawlessVictory ~/polina/a/aa $ touch 1.txt
  15. zhela@FlawlessVictory ~/polina/a/aa $ vim 1.txt
  16. zhela@FlawlessVictory ~/polina/a/aa $ cd ..
  17. zhela@FlawlessVictory ~/polina/a $ cd a
  18. aa/ ab/
  19. zhela@FlawlessVictory ~/polina/a $ cd ab/
  20. zhela@FlawlessVictory ~/polina/a/ab $ vim 2.txt
  21. zhela@FlawlessVictory ~/polina/a/ab $ cd ..
  22. zhela@FlawlessVictory ~/polina/a $ ls
  23. aa  ab
  24. zhela@FlawlessVictory ~/polina/a $ vim 44.txt
  25. zhela@FlawlessVictory ~/polina/a $ touch 123.a
  26. zhela@FlawlessVictory ~/polina/a $ ls
  27. 123.a  44.txt  aa  ab
  28. zhela@FlawlessVictory ~/polina/a $ touch 12.b
  29. zhela@FlawlessVictory ~/polina/a $ cd ..
  30. zhela@FlawlessVictory ~/polina $ ls
  31. a  b  c
  32. zhela@FlawlessVictory ~/polina $ cd b
  33. zhela@FlawlessVictory ~/polina/b $ ls
  34. ba  bb
  35. zhela@FlawlessVictory ~/polina/b $ touch 7.a
  36. zhela@FlawlessVictory ~/polina/b $ cd ba
  37. zhela@FlawlessVictory ~/polina/b/ba $ vim 324.txt
  38. zhela@FlawlessVictory ~/polina/b/ba $ cd ..
  39. zhela@FlawlessVictory ~/polina/b $ cd bb
  40. zhela@FlawlessVictory ~/polina/b/bb $ ls
  41. zhela@FlawlessVictory ~/polina/b/bb $ vim 314.txt
  42. zhela@FlawlessVictory ~/polina/b/bb $ cd ..
  43. zhela@FlawlessVictory ~/polina/b $ ls
  44. 7.a  ba  bb
  45. zhela@FlawlessVictory ~/polina/b $ vim 23.txt
  46. zhela@FlawlessVictory ~/polina/b $ ls
  47. 23.txt  7.a  ba  bb
  48. zhela@FlawlessVictory ~/polina/b $ cd ..
  49. zhela@FlawlessVictory ~/polina $ ls
  50. a  b  c
  51. zhela@FlawlessVictory ~/polina $ cd c
  52. zhela@FlawlessVictory ~/polina/c $ ls
  53. zhela@FlawlessVictory ~/polina/c $ touch 6t.ar
  54. zhela@FlawlessVictory ~/polina/c $ vim 666.txt
  55. zhela@FlawlessVictory ~/polina/c $ cd ..
  56. zhela@FlawlessVictory ~/polina $ ls
  57. a  b  c
  58. zhela@FlawlessVictory ~/polina $ touch 6.tas
  59. zhela@FlawlessVictory ~/polina $ vim 1.txt
  60. zhela@FlawlessVictory ~/polina $ ls
  61. 1.txt  6.tas  a  b  c
  62. zhela@FlawlessVictory ~/polina $ vim solution.c
  63. zhela@FlawlessVictory ~/polina $
  64. zhela@FlawlessVictory ~/polina $
  65. zhela@FlawlessVictory ~/polina $ cat solution.c
  66. #include <stdio.h>
  67. #include <stdlib.h>
  68. #include <string.h>
  69. #include <sys/types.h>
  70. #include <dirent.h>
  71.  
  72. char* txtOpen(char* txtName){
  73.     FILE* txt = fopen(txtName, "r");
  74.     if (txt == NULL){
  75.         printf("ERROR\n");
  76.     return NULL;
  77.     }
  78.     fseek(txt,0,SEEK_END);
  79.     int txtSize = ftell(txt);
  80.     fseek(txt,0,SEEK_SET);
  81.     if(txtSize == 0){
  82.     fclose(txt);
  83.         return NULL;
  84.     }
  85.     char* txtStr = (char*)malloc(sizeof(char)*10000);
  86.     fgets(txtStr, txtSize*sizeof(char),txt);
  87.     fclose(txt);
  88.     return txtStr;
  89. }
  90.  
  91. void list_dir(const char* dirName, char** strsTxt, int* len){
  92.     char current_path[10000];
  93.     strcpy(current_path, dirName);
  94.     DIR *current_dir = opendir(current_path);
  95.     if (current_dir == NULL) return;
  96.     struct dirent* current_dir_file =readdir(current_dir);
  97.     while(current_dir_file){
  98.         int path_len = strlen(current_path);
  99.     strcat(current_path, "/");
  100.     strcat(current_path, current_dir_file->d_name);
  101.         if(current_dir_file->d_type == DT_REG && strstr(current_dir_file->d_name, ".txt") != NULL){
  102.         if((strsTxt[*len] = (char*)txtOpen(current_path)) != NULL)
  103.         (*len)++;
  104.     }
  105.     if (current_dir_file->d_type == DT_DIR && strcmp(".", current_dir_file->d_name) != 0 && strcmp("..",current_dir_file->d_name) != 0) list_dir(current_path,strsTxt,len);
  106.     current_path[path_len] = '\0';
  107.     current_dir_file = readdir(current_dir);
  108.     }
  109.     closedir(current_dir);
  110. }
  111.  
  112. int compare(const void* a, const void* b){
  113.     return atoi(*(char**)a) - atoi(*(char**)b);
  114. }
  115.  
  116. int main(){
  117.     char** strs = (char**)malloc(sizeof(char*)*1000);
  118.     int len = 0;
  119.     int i=0;
  120.     char str[1000];
  121.     FILE* fo;
  122.     fo=fopen("fo","w");
  123.     list_dir(".",strs,&len);
  124.     qsort(strs, len, sizeof(char*), compare);
  125.     for (i=0;i<len;i++) fprintf(fo,"%s\n", strs[i]);
  126.     fclose(fo); //закрываем
  127.     fo=fopen("fo","r");
  128.     while (fgets(str, 1000, fo))
  129.       printf("%s", str);
  130.     fclose(fo);
  131.     for (i=0;i<len;i++) free(strs[i]);
  132.     free(strs);
  133.     return 0;
  134. }
  135. zhela@FlawlessVictory ~/polina $ gcc -c solution.c
  136. zhela@FlawlessVictory ~/polina $ ls
  137. 1.txt  6.tas  a  b  c  solution.c  solution.o
  138. zhela@FlawlessVictory ~/polina $ gcc -o solution.o 123
  139. gcc: error: 123: No such file or directory
  140. gcc: fatal error: no input files
  141. compilation terminated.
  142. zhela@FlawlessVictory ~/polina $ gcc -o solution.o
  143. gcc: fatal error: no input files
  144. compilation terminated.
  145. zhela@FlawlessVictory ~/polina $ gcc -o 123 solution.o
  146. zhela@FlawlessVictory ~/polina $ ls
  147. 123  1.txt  6.tas  a  b  c  solution.c  solution.o
  148. zhela@FlawlessVictory ~/polina $ ./123
  149. 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol 66 ololol olol
  150. 123 twer qwer qwer 1
  151. 125 asdp
  152. 127
  153. 127 sdsd
  154. 129 totot
  155. 555 asd
  156. 1230 slol
RAW Paste Data
Top