I am coding a program which takes a text file as an input, makes the index of the words of it and prints the output(the index) in a file and in the screen.
the input file may be huge. but we KNOW that the maximum variety of the words used in the text file is 200. we don't know what's the maximum of lines and characters of each word. so I should reserve a large number for them. I took the maximum of line 1000 and the maximum characters of each word 100.
I am programming in Turbo C and (I am forced to use that). the compiler allocates just 64kb memory (with the size of the compiler included) and so I have to use MALLOC.
my program is supposed to work in this algorithm:
it reads the input file line by line with fgets. then in the current line, it reads word by word with strtok. so far I have the xth word in yth line. I want to put the words in an array of pointers. so I need a char * word[200]
. and I want to show how many times, which word is repeated in which line. so I need a int index [200][1000]
. if in yth line, the xth word is existed I would do index[x][y]++
.
so now I need to allocate MALLOC memory to these char * word[200]
and int index[200][1000]
. Can anyone help? I tried all the answers to these question and none of them helped.