Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "q2.h"
- int main()
- {
- FILE *fp;
- fp = fopen("test.txt", "r");
- if (fp == NULL)
- {
- printf("FILE COULD NOT BE OPENED\n");
- return 0;
- }
- char *string = calloc(500, 1);
- WordStruct structArray[5000];
- int arraySize = 0;
- while (fscanf(fp, "%s", string) != EOF)
- {
- strcpy(structArray[arraySize].word, string);
- // printf("%s ", string);
- arraySize++;
- }
- int i = 0;
- int j = 0;
- for (i = 0; i < arraySize; i++)
- {
- for (j = 0; j < arraySize; j++)
- {
- if (strcmp(structArray[i].word, structArray[j].word) < 0)
- {
- WordStruct temp = structArray[i];
- structArray[i] = structArray[j];
- structArray[j] = temp;
- }
- }
- }
- WordStruct newArray[3000];
- float wordCount = 1;
- float highestFrequency = 0;
- int freqIndex = 0;
- j = 0;
- for (i = 0; i < arraySize - 1; i++)
- {
- while ((strcmp(structArray[i].word, structArray[i + 1].word) == 0))
- {
- wordCount++;
- i++;
- }
- structArray[i].frequency = wordCount / 10; //change
- if (structArray[i].frequency > highestFrequency)
- {
- highestFrequency = structArray[i].frequency;
- freqIndex = j;
- }
- newArray[j] = structArray[i];
- wordCount = 1;
- j++;
- }
- q2(newArray, j);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement