I am trying to work with an example in book K and R for this topic, but I'm afraid.
I need an array of Char arrays, as a result, each element of the Father array points to an array of characters (string). Basically, I read from a file, lines at a time, saving each line in an array, and then trying to save this array into another array, which I can then sort through qsort.
But I canβt handle it anywhere! Anyhelp on my code is very appreciated, that is, where to go, where I come from!
EDIT: the problem is that the print function does not print my words, which should be in an array of arrays, instead just print garbage, the main problem is that I'm not sure if I delete links all correctly or not, regardless from whether I am adding it to the array of arrays correctly, etc.
Sincerely.
#define MAXLINES 5000 #define MAXLEN 1000 char *lineptr[MAXLINES]; void writelines(char *lineptr[], int nlines); int main(int argc, char *argv[]) { int nlines = 0, i, j, k; char line[MAXLEN]; FILE *fpIn; fpIn = fopen(argv[1], "rb"); while((fgets(line, 65, fpIn)) != NULL) { j = strlen(line); if (j > 0 && (line[j-1] == '\n')) { line[j-1] = '\0'; } if (j > 8) { lineptr[nlines++] = line; } } for(i = 0; i < nlines; i++) printf("%s\n", lineptr[i] ); return 0; }
source share