My assignment is to create a function that
Prints a table indicating the number of occurrences of each different words in the text in the same order in which they appear
I'm using gets()
to read in the string, a function to tokenize each word in the string and store it in a 2-dimensional array, and need help figuring out how to make one that analyzes the array for duplicates.
Here's the tokenizer function:
void tokeniz(char *array)
{
char words[arraySize][arraySize] = { NULL };
const char s[2] = " ";
char *token;
int i = 0;
token = strtok(array, s);
while (token != NULL)
{
strcpy(words[i], token);
token = strtok(NULL, s);
i++;
}
wotable(words);
}
Earlier in the program, I have a function to count the number of times each character appears in the string (pre-tokenization). Would I be able to repurpose some of that code?
void alpha(char *array)
{
char character = 'a';
int numberOf = 0, tcc = 0;
for (character = 'a'; character <= 'z'; character++)
{
tcc = (tcc + numberOf);
numberOf = 0;
for (int i = 0; i < arraySize; i++)
if (*(array + i) == character)
numberOf++;
if (numberOf != 0)
printf("\nNumber of %c's:\t\t%d\n", character, numberOf);
}
printf("\nTotal character count:\t%d\n\n- - - - - - - - - - - - - -", tcc);
}