Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void main()
- {
- char **words = NULL, temp[80] = "\0" ;
- int n = 0 , j ;
- printf ("Insira strings (para acabar insira 0):\n") ;
- while (strcmp(temp , "0\n") != 0)
- {
- fgets (temp , 80 , stdin) ;
- if (strcmp(temp , "0\n") == 0 ) break ;
- for (j = 0 ; j < n ; j++) if (strcmp(temp , words[j]) == 0) break ;
- if (j >= n)
- {
- words = (char **)realloc (words,(n + 1) * sizeof(char*)) ;
- words[n] = (char *)malloc ((strlen(temp) + 1) * sizeof(char)) ;
- strcpy ( words[n++], temp ) ;
- }
- }
- for (j = 0 ; j < n ; j++) printf ("%s" , words[j]) ;
- free (words) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment