Hi,
I want to assign values to a string array, which is declared as char** stringArr, by reading a file. One line of the file is to be one element of the string array. My code is as the following:
Code:
char** stringArr;
char* l = malloc(MAX_CHAR); //MAX_CHAR is defined
char** lp = stringArr;
int i = 0;
while( fget(l, MAX_CHAR, fp ) != NULL ){ //fp is the pointer to a opened file
*lp++ = l;
i++;
}
After that, when I checked the content of stringArr as the following, there are errors.
Code:
int j;
for ( j = 0; j < i; j++ ){
printf("%s", *stringArr[j]);
}
Just quite confused what goes wrong here?
Many thanks!
Regards,
Paul