1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <stdio.h>
#include <locale.h>
#include <string.h>
#define S 256
#define W 30
#define Z ",."
int main (void){
int i, j, c = 0;
char str[S], *ptr = 0, *word[W] = {0};
do{
printf ("You are given a sequence containing from 3 to 30 words, each of which contains from 1 to 5 capital Latin letters; between adjacent words - a comma, after the last word - a period. Print: all words that occur more than once in the sequence.\n\n");
printf ("Enter the string: \n");
if (scanf("%255[^\n]", str) == 1 && fgetc(stdin) == '\n'){
for (ptr = strtok(str,Z); ptr != 0 && c < W; c++, ptr = strtok(0,Z))
word[c] = ptr;
printf ("Words:\n");
for (i = 0; i < c; i++)
printf ("%s\n", word[i]);
printf ("\n");
printf ("Duplicate words:\n");
for (i = 0; i < c; i++){
for (j = 0; j < c; j++){
if (i != j && strcmp(word[i], word[j]) == 0)
printf("%s\n", word[i]);
}
}
}
}
while (getchar() != 27);
}
|