Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Закинуть этот кусок в файл reshift.c
- --------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "realezat.h"
- int reshift(const char *in, int n, char *cru, int *stu)
- {
- char c;
- FILE *input;
- char filename[32];
- int i, s;
- const char include_prefix[] = "include<";
- if (n > 5)
- {
- printf("!!!!!!!!!!!\n");
- return 0;
- }
- input = fopen(in, "r");
- if (!input)
- {
- printf("^^^^^^^^^^^^^^");
- fclose(input);
- return 0;
- int pokl=0;
- }
- i=0;
- while ((c = fgetc(input)) != EOF)
- {
- if (c == include_prefix[i])
- {
- i++;
- if (include_prefix[i] == '\0')
- {
- for (i = 0; i < 32&&(c=fgetc(input))!='>'; i++)
- {
- if (c ==EOF)
- {
- printf("ssss\n");
- fclose(input);
- return 1;
- }
- filename[i] = c;
- }
- if (c == '>')
- {
- filename[i] = '\0';
- n++;
- reshift(filename, n, cru, stu);
- }
- if(i==32)
- {
- printf("##########\n");
- fclose(input);
- return 0;
- }
- i = 0;
- }
- }
- else
- {
- for (s = 0; s < i; s++)
- {
- stu[0]++;
- cru=(char*)realloc(cru, stu[0]*sizeof(char));
- cru[stu[0]]=include_prefix[s];
- }
- i = 0;
- stu[0]++; // и не сматчившийся символ тоже выводим.
- cru=(char*)realloc(cru, stu[0]*sizeof(char));
- cru[stu[0]]=c;
- }
- }
- stu[0];
- fclose (input);
- return 1;
- }
- -------------------------------------------
- ___________________________________________
- -------------------------------------------
- Закинуть в файл test.c
- ----------------------
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "realezat.h"
- int main (void)
- {
- int i;
- FILE *out;
- int *stu;
- char *cru;
- out=fopen("output.txt", "w+");
- stu=(int*)malloc(sizeof(int)*1);
- stu[0]=0;
- cru=(char*)malloc(sizeof(char)*1);
- if(reshift("input.txt", 1, cru, stu)!=0)
- {
- for(i=0; i<stu[0]; i++)
- {
- fprintf(out, "%c", cru[i]);
- }
- free(cru);
- free(stu);
- fclose(out);
- return 0;
- }
- fclose(out);
- free(cru);
- free(stu);
- return -1;
- }
- -------------------------------------------
- ___________________________________________
- -------------------------------------------
- Закинуть в файл realezat.h
- ----------------------
- #ifndef FMODULE_H
- #define FMODULE_H
- int reshift(const char *in, int n,char *cru, int *stu);
- #endif
Add Comment
Please, Sign In to add comment