Guest User

Untitled

a guest
Jun 3rd, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. Закинуть этот кусок в файл reshift.c
  2. --------------------
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "realezat.h"
  7. int reshift(const char *in, int n, char *cru, int *stu)
  8. {
  9. char c;
  10. FILE *input;
  11. char filename[32];
  12. int i, s;
  13. const char include_prefix[] = "include<";
  14. if (n > 5)
  15. {
  16. printf("!!!!!!!!!!!\n");
  17. return 0;
  18. }
  19.  
  20. input = fopen(in, "r");
  21. if (!input)
  22. {
  23. printf("^^^^^^^^^^^^^^");
  24.  
  25. fclose(input);
  26. return 0;
  27. int pokl=0;
  28. }
  29. i=0;
  30.  
  31. while ((c = fgetc(input)) != EOF)
  32. {
  33. if (c == include_prefix[i])
  34. {
  35. i++;
  36.  
  37. if (include_prefix[i] == '\0')
  38. {
  39. for (i = 0; i < 32&&(c=fgetc(input))!='>'; i++)
  40. {
  41. if (c ==EOF)
  42. {
  43. printf("ssss\n");
  44. fclose(input);
  45. return 1;
  46. }
  47.  
  48.  
  49. filename[i] = c;
  50. }
  51. if (c == '>')
  52. {
  53. filename[i] = '\0';
  54. n++;
  55.  
  56. reshift(filename, n, cru, stu);
  57.  
  58.  
  59. }
  60.  
  61. if(i==32)
  62. {
  63. printf("##########\n");
  64.  
  65. fclose(input);
  66. return 0;
  67. }
  68.  
  69. i = 0;
  70. }
  71. }
  72. else
  73. {
  74. for (s = 0; s < i; s++)
  75. {
  76. stu[0]++;
  77.  
  78. cru=(char*)realloc(cru, stu[0]*sizeof(char));
  79. cru[stu[0]]=include_prefix[s];
  80. }
  81.  
  82. i = 0;
  83.  
  84.  
  85. stu[0]++; // и не сматчившийся символ тоже выводим.
  86. cru=(char*)realloc(cru, stu[0]*sizeof(char));
  87. cru[stu[0]]=c;
  88. }
  89. }
  90. stu[0];
  91. fclose (input);
  92. return 1;
  93. }
  94. -------------------------------------------
  95. ___________________________________________
  96.  
  97. -------------------------------------------
  98. Закинуть в файл test.c
  99. ----------------------
  100. #include <stdio.h>
  101. #include <string.h>
  102. #include <stdlib.h>
  103. #include "realezat.h"
  104. int main (void)
  105. {
  106. int i;
  107. FILE *out;
  108. int *stu;
  109. char *cru;
  110. out=fopen("output.txt", "w+");
  111. stu=(int*)malloc(sizeof(int)*1);
  112. stu[0]=0;
  113.  
  114. cru=(char*)malloc(sizeof(char)*1);
  115.  
  116. if(reshift("input.txt", 1, cru, stu)!=0)
  117. {
  118.  
  119. for(i=0; i<stu[0]; i++)
  120. {
  121. fprintf(out, "%c", cru[i]);
  122. }
  123. free(cru);
  124. free(stu);
  125. fclose(out);
  126. return 0;
  127. }
  128. fclose(out);
  129. free(cru);
  130. free(stu);
  131.  
  132. return -1;
  133. }
  134. -------------------------------------------
  135. ___________________________________________
  136.  
  137. -------------------------------------------
  138. Закинуть в файл realezat.h
  139. ----------------------
  140. #ifndef FMODULE_H
  141. #define FMODULE_H
  142. int reshift(const char *in, int n,char *cru, int *stu);
  143. #endif
Add Comment
Please, Sign In to add comment