Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- char **groups, word[30], **store, n = 0, k = 0;
- store = malloc(1*sizeof(char *));
- if (store == NULL) exit(1);
- for (;;) {
- printf("Enter word: ");
- if (scanf("%s", word) == EOF) break;
- store[n] = malloc((strlen(word)+1)*sizeof(char));
- if (store[n] == NULL) exit(1);
- strcpy(store[n], word);
- n++;
- store = realloc(store, (n+1)*sizeof(char *));
- if (store == NULL) exit(1);
- }
- for (int i=0; i<n; i++) {
- printf("%s ", store[i]);
- }
- printf("\n");
- for (int i=0; i<n; i++) {
- for (int j=0; j<strlen(store[i])-1; j++) {
- for (int l=(j+1); l<strlen(store[i]); l++) {
- if (store[i][j] > store[i][l]) {
- char aux = store[i][j];
- store[i][j] = store[i][l];
- store[i][l] = aux;
- }
- }
- }
- }
- printf("Sorted list: ");
- for (int i=0; i<n; i++) {
- printf("%s ", store[i]);
- }
- char **dupl = malloc(n*sizeof(char *));
- for (int ii = 0; ii < n; ii++) {
- dupl[ii] = strdup(store[ii]);
- }
- printf("\n");
- for (int i=0; i<n; i++) {
- for (int j=0; j<strlen(dupl[i]); j++) {
- if (dupl[i][j] == dupl[i][j+1]) {
- for (int l=j; l<strlen(dupl[i])-1; l++) {
- dupl[i][l] = dupl[i][l+1];
- }
- dupl[i][strlen(dupl[i]) - 1] = '\0';
- j--;
- }
- }
- }
- printf("Deduplicated list: ");
- for (int i=0; i<n; i++) {
- printf("%s ", dupl[i]);
- }
- printf("\n");
- free(dupl);
- free(store);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement