Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- struct key {
- char *word;
- int count;
- int score;
- } mas[] = {
- "auto", 0,1,
- "break", 0,1,
- "case", 0,1,
- "char", 0,1,
- "const", 0,1,
- "continue", 0,1,
- "default", 0,1,
- "unsigned", 0,1,
- "void", 0,1,
- "volatile", 0,1,
- "while", 0,1,
- };
- struct key arr[1000];
- int gethash(char *slovo, int line);
- int main()
- {
- printf("Список ключевых слов ");
- int x=0;
- int hash[10];
- int j;
- int help;
- int t;
- int temp;
- for (int z=0; z<=1000; z++)
- {
- arr[z].count=0;
- arr[z].score=0;
- }
- for(x=0; x<=10; x++)
- {
- hash[x]=0;
- j=0;
- t=strlen(mas[x].word);
- while(t > 0)
- {
- help=mas[x].word[j];
- hash[x]= hash[x] + help;
- j++;
- t--;
- }
- temp=hash[x];
- arr[temp].score=1;
- arr[temp].word=mas[x].word;
- printf("\n %s \n", mas[x].word);
- }
- int line;
- int p;
- char c;
- char *ukaz[100];
- char slova[1000][1000];
- int i1,j1=0;
- int k=0;
- int q=0;
- char name[100];
- printf("Введите название файла ");
- scanf("%s",name);
- FILE *f;
- if ((f=fopen(name, "r"))==0)
- {
- printf("Неверное имя файла");
- return 0;
- }
- while ((c=fgetc(f))!=EOF)
- {
- if (isspace(c)!=0)
- {
- ukaz[j1]=slova[j1];
- j1++;
- i1=0;
- }
- else{
- slova[j1][i1]=c;
- i1++;
- }
- }
- fclose(f);
- for (q=0; q<j1; q++)
- {
- line=strlen(ukaz[q]);
- p=gethash(ukaz[q],line);
- if (p<=1000 && arr[p].score!=0)
- {
- arr[p].count++;
- }
- }
- for (int z=400; z<=1000; z++)
- {
- if (arr[z].score!=0)
- {
- printf("Ключевое слово %s встретилось \t",arr[z].word);
- printf("%d раз(а)\n",arr[z].count);
- }
- }
- }
- int gethash(char *slovo, int line)
- {
- int hash=0;
- int j=0;
- int help;
- while(line>0)
- {
- help=slovo[j];
- hash= hash+ help;
- j++;
- line--;
- }
- return hash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement