I am trying to read something from a txt file using fscanf
. I am only reading a word in each time. And I am counting how many words I've collected. So that I can create a dynamic array with the count of words. Each element of array will contain a word. But I don't know how. Here is my code
pFile = fopen(inFile, "r");
char *chr;
if(pFile != NULL) // Process if the file is not empty
{
while(!feof(pFile))
{
chr = (char*)malloc(sizeof(char*));
num++;
fscanf(pFile, "%s", chr);
}
printf("%s",chr);
}
And my example of the txt file is like that: hello world