mihainan

Nan Mihai - Pointeri

Mar 23rd, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char **despartire_text(int *nr, char *text)
  6. {
  7.      int n;
  8.      char **vect;
  9.      char separator[]=",. ?!\n";
  10.      char *aux;
  11.      int i;
  12.      vect = (char **) malloc(200*sizeof(char *));
  13.      n = 0;
  14.      for(i=0;i<200;i++)
  15.      {
  16.              *vect = (char *) malloc(50*sizeof(char));
  17.      }
  18.      aux = strdup(text);
  19.      aux = strtok(aux, separator);
  20.      while(aux)
  21.      {
  22.              vect[n] = aux;
  23.              aux = strtok(NULL, separator);
  24.              n++;
  25.      }    
  26.      *nr = n;
  27.      return vect;
  28. }
  29.  
  30. int main()
  31. {
  32.           char *text1, *text2, **cuv1, **cuv2, *aux1, *aux2;
  33.           int nr1, nr2, i, j, ok, rez;
  34.           text1 = (char *) malloc(2000*sizeof(char));
  35.           text2 = (char *) malloc(2000*sizeof(char));
  36.           printf("Introduceti primul text!\n");
  37.           fgets(text1, 2000, stdin);
  38.           printf("Introduceti al doilea text!\n");
  39.           fgets(text2, 2000, stdin);
  40.           printf("Cuvintele comune sunt urmatoarele:\n");
  41.           cuv1 = despartire_text(&nr1, text1);
  42.           cuv2 = despartire_text(&nr2, text2);
  43.           for(i=0;i<nr1;i++)
  44.           {
  45.                 for(j=0;j<nr2;j++)
  46.                 {
  47.                       aux1 = strdup(cuv1[i]);
  48.                       aux2 = strdup(cuv2[j]);
  49.                       rez = strcmp(aux1, aux2);
  50.                       free(aux1);
  51.                       free(aux2);
  52.                       if(rez == 0)
  53.                              printf("%s\n", cuv1[i]);
  54.                 }
  55.           }
  56.           return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment