Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char **despartire_text(int *nr, char *text)
- {
- int n;
- char **vect;
- char separator[]=",. ?!\n";
- char *aux;
- int i;
- vect = (char **) malloc(200*sizeof(char *));
- n = 0;
- for(i=0;i<200;i++)
- {
- *vect = (char *) malloc(50*sizeof(char));
- }
- aux = strdup(text);
- aux = strtok(aux, separator);
- while(aux)
- {
- vect[n] = aux;
- aux = strtok(NULL, separator);
- n++;
- }
- *nr = n;
- return vect;
- }
- int main()
- {
- char *text1, *text2, **cuv1, **cuv2, *aux1, *aux2;
- int nr1, nr2, i, j, ok, rez;
- text1 = (char *) malloc(2000*sizeof(char));
- text2 = (char *) malloc(2000*sizeof(char));
- printf("Introduceti primul text!\n");
- fgets(text1, 2000, stdin);
- printf("Introduceti al doilea text!\n");
- fgets(text2, 2000, stdin);
- printf("Cuvintele comune sunt urmatoarele:\n");
- cuv1 = despartire_text(&nr1, text1);
- cuv2 = despartire_text(&nr2, text2);
- for(i=0;i<nr1;i++)
- {
- for(j=0;j<nr2;j++)
- {
- aux1 = strdup(cuv1[i]);
- aux2 = strdup(cuv2[j]);
- rez = strcmp(aux1, aux2);
- free(aux1);
- free(aux2);
- if(rez == 0)
- printf("%s\n", cuv1[i]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment