I was tryin to read a text file and return two dimensional char array to main function. The text file ips.txt as following:
hello1
hello2
hello3
My code as following:
define BUF 20
define TOT 3
char ** getIps(){
char line[TOT][BUF];
FILE *plist = NULL;
int i = 0;
int total = 0;
plist = fopen("ips.txt", "r");
while(fgets(line[i], BUF, plist)) {
line[i][strlen(line[i]) - 1] = '\0';
i++;
}
return line;
}
int main(void) {
int i=0;
char (*line)[TOT];
line=getIps();
int total=3;
for(i = 0; i < total; ++i)
printf("%s\n", line[i]);
return 0;
}
The main function print out nothing, Not sure where I did wrong?