Advertisement
Guest User

Untitled

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