I'm trying to read a text file into an array of strings, but struggling. The lines counter works correctly, but it's not making the currentLine expand, and the printf isn't printing anything in any case.
char* readFile() {
FILE *fp = fopen(inputPath, "r");
char* currentLine = "";
char* allLines[] = {};
int lines = 0;
do {
char ch = fgetc(fp);
printf("%s", ch);
if (ch == '\n') {
allLines[lines] = currentLine;
lines++;
currentLine = "";
} else {
currentLine += ch;
printf("%s", currentLine);
}
} while (!feof(fp));
#ifdef debug
for (int i = 0; i < (sizeof(allLines) / sizeof(char*)); i++){
printf("%d: %s\n", i, allLines[i]);
}
#endif
fclose(fp);
return lines;
}
Not sure what to change to fix this? inputPath is just the name of the text file for the time being.