i have an assignment for collage to build a dynamic dictionary, the assignment must be used with pointers and dynamic allocation ( i understand that this is trivial stuff that i am saying here). any how i have been trying to play with the code and this is what i have come up with. im sure i have mistakes in here, my problem is actualy how do implement the memory allocation right, and then how to store the words/definitions in that memory that i allocate.
printf("Please enter the amount of words in the dictionary.\n");
scanf("%d",&numOfWords);
getchar();
wordsArr = (char***)malloc(3 * sizeof(char**));
for (int i = 0; i < numOfWords; i++)
{
printf("Please enter the word and how many defenitions it has (1 or 2).\n");
scanf("%s %d",&wBuffer[i],&defs);
getchar();
wordsArr[i]=(char**)malloc(strlen(wBuffer)*sizeof(char*)+1);
strcpy(*wordsArr[i],wBuffer);
for (int j = 0; j < defs; j++)
{
printf("Enter the %d is:\n",i);
gets(dBuffer);
wordsArr[i][j]=(char*)malloc(strlen(dBuffer)*sizeof(char)+1);
strcpy(wordsArr[i][j],dBuffer);
}
}
//Dont mind this just for the print test
for (int i = 0; i < numOfWords; i++)
{
for (int j = 0; j < defs; j++)
{
printf("%s",wordsArr[i][j]);
}
}
}