Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2012
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <locale.h>
  5.  
  6. char* enterSeperators()
  7. {
  8.     printf("vvedite simvoly-razdeliteli\n");
  9.     char *sepr=(char*)malloc(81*sizeof(char));
  10.     gets(sepr);
  11.     sepr[strlen(sepr)]='\0';
  12.     return sepr;
  13. }
  14.  
  15. int enterAmount()
  16. {
  17.     int z;
  18.     printf("kol-vo raznyh simvolov-razdeliteley:\n");
  19.     scanf("%d", &z);
  20.     return z;
  21. }
  22.  
  23. char** enterLines(int z, char *sepr)
  24. {
  25.     printf("sepr: %s   %i\n",sepr, z);
  26.     int c=0,i,l,f=0,j,n;
  27.     char line[81], **x;
  28.     x = (char**) malloc(sizeof(char*));
  29.     printf("\nVvedite stroki: \n");
  30.     do
  31.     {
  32.         l=0;
  33.         n=0;
  34.         //printf("!!!!!!\n");
  35.         gets(line);
  36.         //printf("???????\n");
  37.         char *r=(char*)malloc(strlen(line)*sizeof(char));
  38.         x[c] = (char*) malloc(strlen(line)*sizeof(char));
  39.         strcpy(x[c], line);
  40.         for(i=0; i<strlen(line); i++)
  41.         {
  42.             for(j=0;j<strlen(r);j++)
  43.             {
  44.                 if(x[c][i]==r[j]) {f=0; break;} else f=1;
  45.  
  46.             }
  47.             for(j=0;j<strlen(sepr);j++)
  48.             {
  49.                 if(x[c][i]==sepr[j] && f)
  50.                 {
  51.                     r[n]=sepr[j];
  52.                     l++;
  53.                     n++;
  54.                 }
  55.             }
  56.             r[strlen(r)]='\0';
  57.         }
  58.         printf("r: %s   l: %i     c:%i\n", r,l,c);
  59.         c++; //gq=c;
  60.        for(i=0; i<strlen(r); i++) r[i] = '0';
  61.     }
  62.     while(l<z);
  63.     x[0][0]=c;
  64.     return x;
  65. }
  66.  
  67. /////////////////////////////////////////////////////
  68.  
  69. char** deleteWord(char **x, char *sepr)
  70. {
  71.     int c=1, q=0, i=0, e=0, m;
  72.     int start=0,final, wordLen;
  73.     char **y;
  74.     printf("Задайте длинну слова:\n");
  75.     scanf("%d", &wordLen);
  76.     y = (char**) malloc(sizeof(char*));
  77.     y[0]=(char*)malloc(1*sizeof(char));
  78.     do{
  79.         start=0;
  80.             y[c] = (char*) malloc(strlen(x[c])*sizeof(char));
  81.             e=0;
  82.             i=start;
  83.             final=0;
  84.     do {
  85.         for(m=0;m<strlen(sepr);m++)
  86.         if(x[c][i]==sepr[m] || i==strlen(x[c]))
  87.         {
  88.             final=i;
  89.             if((final-start-1)<wordLen && !(final-start==wordLen && start==0)&& !(final==strlen(x[c])&&(final-start-1==0)))
  90.             {
  91.              // НЕ записываем в массив y
  92.              start=final;
  93.             }
  94.             else
  95.             {
  96.                 //запишем в массив y
  97.                 for(q=start;q<(final);q++,e++)
  98.                     y[c][e]=x[c][q];
  99.                 start=final;
  100.             }
  101.         }
  102.         i++;
  103.     }while(i<=strlen(x[c]));
  104.     y[c][e]='\0';
  105.     c++;
  106.     } while(c<x[0][0]);
  107.     y[0][0]=x[0][0];
  108.     return y;
  109. }
  110.  
  111. void output(char **y)
  112. {
  113.     int c;
  114.     printf("\n\nВывод конечного массива\n\n");
  115.     for(c=1;c<y[0][0];c++)
  116.     {
  117.         printf("%s", y[c]); printf("\n");
  118.     }
  119. }
  120.  
  121. int main()
  122. {
  123.     setlocale(LC_ALL, "Russian");
  124.     char *sepr, **x, **y;
  125.     int z;
  126.     sepr=enterSeperators();
  127.     z=enterAmount();
  128.     x=enterLines(z, sepr);
  129.     y=deleteWord(x, sepr);
  130.     output(y);
  131.     free(x); free(y);
  132.     return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement