Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- #include <ctype.h>
- #include <stdlib.h>
- const int m1 = 10, n1 = 20, N = 2;
- int found(char **book, char *word, int *count, int n) {
- int i, j, f;
- for(i = 0, f = 1; (i < n) && (f); i++)
- if(strcmp(word, book[i]) == 0) {
- f = 0;
- count[i]++;
- }
- if(f) {
- strcpy(book[n], word);
- n++;
- }
- return n;
- }
- int input(char str[], int n1) {
- int c, i = 0;
- c = getchar();
- while((c != EOF) && (c != '\n')) {
- if(i > strlen(str))
- realloc(str, n1 * sizeof(char));
- str[i] = (char) c;
- c = getchar();
- i++;
- }
- if(c == '\n')
- return 1;
- else
- return 0;
- }
- int main() {
- char **book, *str, *word; int *count, i, j, n = 0;
- book = (char **) malloc(m1 * sizeof(char));
- for(i = 0; i < m1; i++)
- book[i] = (char *) malloc((n1 + 1) * sizeof(char));
- str = (char *) malloc((n1 + 1) * sizeof(char));
- word = (char *) malloc((n1 + 1) * sizeof(char));
- count = (int *) malloc(m1 * sizeof(char));
- for(i = 0; i < m1; i++)
- count[i] = 0;
- while(input(str, n1)) {
- for(i = 0, j = 0; str[i] != '\0'; i++)
- if((str[i] == ' ') || (str[i] == '\n')) {
- word[j] = '\0';
- n = found(book, word, count, n);
- j = 0;
- }
- else {
- word[j] = str[j];
- j++;
- }
- }
- for(i = 0; i < n; i++)
- if(count[i] >= N)
- fputs(book[i], stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement