I'm trying to keep the words from a file into an array but I only read the first 8.
My code below.
#define BUF 128 /* can change the buffer size as well */
char ** readFileContentArray(char* filename){
int lines = 128;
char ** strLines = (char **)malloc(sizeof(char*)*lines);
FILE *plist = NULL;
int i = 0;
char line[4];
plist = fopen(filename, "r");
while(fgets(line, BUF, plist)) {
if(i >= lines){
strLines = (char **)realloc(strLines, (lines*2) * sizeof(char *));
lines = lines*2;
}
strLines[i] = strdup(line);
i++;
}
return strLines;
}
The file that I'm reading is formed like below:
aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
iiii
jjjj