Hello i am trying to find the frequncey of words in tow dimensional arry but im having problem with my codes so far this is what i have done i tried to find whats wrong using debugger but i cant find anything usefull im new to coding so i would be really happy if someone can tell me the problem
I pointed out where im having problem in my code
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void freeFunction(char** arry, int size);
void insertArry(char** words, int countWords);
void wordFrequency(char** words, int countWords);
int main()
{
char** words=NULL;
int count = NULL;
insertArry(words, &count);
wordFrequency(words,count);
}
void insertArry(char** words, int* countWords)
{
char buffer[11];
int numberC;
printf("How many words?: ");
scanf("%d", &numberC);
getchar();
words = (char**)malloc(numberC * sizeof(char*));
if (words == NULL)
{
printf("No memory");
exit(1);
}
for (int i = 0; i < numberC; i++)
{
printf("Enter word: ");
gets_s(buffer, 11);
words[i] = (char*)malloc(strlen(buffer) + 1);
if (words == NULL)
{
freeFunction(words, i);
exit(1);
}
strcpy(words[i], buffer);
}
*countWords = numberC;
}
void freeFunction(char** arry, int size){
printf("No memory");
for (int j = 0; j < size; j++)
{
free(arry[j]);
}
free(arry);
}
void wordFrequency(char** words, int countWords)
{
int counter = 0;
for (int i = 0; i < countWords; i++) {
for (int j = i + 1; j < countWords; j++)
{
if(strcmp(words[i],words[j])==0) /// ***THIS IS WHERE MY PROBLEM RELAY ITS GIVING ME WEIRD ADDRESSES***
counter += 1;
}
printf("%s:%d",words[i], counter);
counter = 0;
}
}