Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define true 1
- #define false 0
- int validateWord(char* str)
- {
- int lettersCounter = strlen(str);
- if(((str[0] >= 'a') && (str[0] <= 'z')) || ((str[0] >= 'A') && (str[0] <= 'Z')))
- {
- return true;
- }
- else if(str[1] == '\0')
- {
- return false;
- }
- else if(((str[lettersCounter/2] >= 'a') && (str[lettersCounter/2] <= 'z')) || ((str[lettersCounter/2] >= 'A') && (str[lettersCounter/2] <= 'Z')))
- {
- return true;
- }
- return false;
- }
- int countWords(FILE *f)
- {
- int count = 0;
- char buff[255];
- while (fscanf(f, "%s", buff) != EOF)
- {
- if(validateWord(buff))
- count++;
- }
- return count;
- }
- void ednakvi(FILE *fp, int wordCounter)
- {
- rewind(fp);
- int i = 0,k = 0,cnt = 1;
- char *arr[wordCounter];
- for (i=0; i<wordCounter; i++)
- arr[i] = (char *)malloc(255);
- i = 0;
- while(fscanf(fp, "%s", arr[i]) != EOF)
- {
- if(validateWord(arr[i]))
- {
- i++;
- }
- }
- for(i=0;i < wordCounter;i++)
- {
- if(arr[i][0] != '-')
- {
- for(k = i+1;k < wordCounter;k++)
- {
- if(!strcmp(arr[i],arr[k]))
- {
- arr[k][0] = '-';
- cnt++;
- }
- }
- }
- else
- {
- cnt = 0;
- }
- if(cnt >= 1)
- {
- printf("%s : %d\n",arr[i],cnt);
- }
- cnt = 1;
- }
- }
- int main(int agrc, char* argv[])
- {
- int wordCount = 0;
- FILE *rFile = fopen(argv[1], "r");
- wordCount = countWords(rFile);
- printf("%d\n", wordCount);
- ednakvi(rFile,wordCount);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement