Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Темирхан Мамаев on 05/12/2019.
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <limits.h>
- int find_sub(char *str, char fs){
- if (strchr(str, fs)) {
- return 1;
- }
- return 0;
- }
- char **podstr_split(char **s, int size_arr, char* fs, char* ls){
- int n = 0;
- char **podstr_arr = malloc(sizeof(char*) * 5);
- char **ps = podstr_arr;
- for(char **str = s; str < s + size_arr; str++){
- char *q = *str, *p = *str;
- while((q = strstr(q, fs)) && (p = strstr(q, ls))){
- *ps = malloc(sizeof(char) * (p - q - 1));
- strncpy(*ps, (q + 2), (p - q - 2));
- *(*ps + (p - q - 2)) = '\0';
- ps++;
- n++;
- q++;
- if (n % 5 == 0) {
- podstr_arr = realloc(podstr_arr, sizeof(char*) * (n + 5));
- ps = podstr_arr + n;
- }
- }
- }
- *(podstr_arr + n) = NULL;
- return podstr_arr;
- }
- void vstav_char(char *s, char ps, char h){
- char *p = s, *q;
- while((p = strchr(p, h))){
- q = strchr(p, '\0');
- while(q > p){
- *(q + 1) = *q;
- q--;
- }
- *(p + 1) = ps;
- p++;
- }
- }
- int main(int argc, const char * argv[]) {
- FILE *f;
- char buf[80], **p = NULL, **str = NULL, **s, *p_max, **podstr;
- int n = 0;
- if (!(f = fopen("data.txt", "rb"))) {
- printf("file don't exist");
- return 1;
- }
- else{
- while (!feof(f)) {
- str = (char**)malloc(sizeof(char*) * 5);
- p = str;
- while (!feof(f)) {
- fgets(buf, 79, f);
- *p = (char*)malloc((strlen(buf) + 1) * sizeof(char));
- strcpy(*p, buf);
- p++;
- n++;
- if (n % 5 == 0) {
- str = (char**)realloc(str, sizeof(char*) * (n + 5));
- p = str + n;
- }
- }
- }
- }
- podstr = podstr_split(str, n, "[[", "]]");
- puts(p_max);
- for(s = str; s < str + n; s++){
- vstav_char(*s, '0', '1');
- puts(*s);
- free(*s);
- }
- printf("\n__________________________________\n\n");
- for(s = podstr; *s; s++){
- puts(*s);
- free(*s);
- }
- free(podstr);
- free(str);
- fclose(f);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement