Indeed, i'm not quite sure to understand why it's not working for you because i just tested it and it does work, and got no warnings concerning incompatible pointer types. I use Visual Studio 2005, with the compiling as C code option and warning set to max.
Here is the source code
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define NOM_FICH "test.txt"
#define MAX_LEN 200
int LoadWordList(char *fname, char ***list)
{
FILE *fp = fopen(fname, "r");
char ch;
char string[MAX_LEN];
int linecount = 0, i, len;
if(! fp)
{
printf("Error: Unable to open wordlist file.\n");
exit(EXIT_FAILURE);
}
while((ch = fgetc(fp)) != EOF)
if(ch == '\n') linecount++;
rewind(fp);
*list = malloc(linecount * sizeof(char *));
for(i=0; i<linecount; i++)
{
fgets(string, MAX_LEN, fp);
len = strlen(string);
(*list)[i] = malloc((len + 1) * sizeof(char));
strcpy((*list)[i], string);
}
return linecount;
}
int main()
{
char **list;
int i;
int nbElement;
nbElement = LoadWordList(NOM_FICH, &list);
for (i = 0; i < nbElement; i++)
{
printf("%s", list[i]);
}
return 0;
}
And here the "test.txt" file i was using
Code:
this
is
a
random
test