Hi there, two questions if you all don't mind.
First of all, I have a function that reads in a text file here, and I'm trying to figure out how to change it to use dynamic memory allocation to set the size of the dictionary array:
Code:
int main(){
char dict [10000][20];
int size;
size = get_dict(dict);
}
int get_dict(char dict[][20]) {
FILE * ifp = fopen("dictionary.txt", "r");
int size, i;
fscanf(ifp, "%d", &size);
for (i=0; i<size; i++)
fscanf(ifp, "%s", dict[i]);
fclose(ifp);
return size;
}
I just don't know the small details of syntax and all my attempts to change it have not worked so far. Also I'm not entirely sure of the proper syntax to pass around the dictionary array "dict[][]" to other functions once it's converted to DMA...
Secondly, whether or not I can figure out how to dynamically set my array or not, I'd like to set up a function that will perform a binary search through the dictionary file.
The dictionary file is [10000] length and is in alphabetical order.
I understand how to perform a binary search with an array of integers, but I'm not really sure how that translates to an array of characters.
I've spent a lot of time searching google and this forum history on the topic of character binary searches, and I can't find anything but some fragmented broken code here and there. If I can just learn the syntax and concepts I can work it into my own project.
Thank you in advance to anyone who takes the time to consider my questions.
-d