P
paktsardines
Dear all,
As of yesterday I have this function:
char ** lines = read_file("filename.txt");
Now, I want to print the contents of lines. A first attempt:
int i=0;
while (lines) {
printf("%s\n",lines);
i++;
}
Seg faults after printing all lines because it tries printing beyond
the end of the array.
How can I determine how many variable-length lines are in the array?
The only way I can think of is to modify readfile so it can be called
as:
int numlines=read_file("filename.txt", lines);
Is there another/better way?
Thanks for any tips,
Pakt.
As of yesterday I have this function:
char ** lines = read_file("filename.txt");
Now, I want to print the contents of lines. A first attempt:
int i=0;
while (lines) {
printf("%s\n",lines);
i++;
}
Seg faults after printing all lines because it tries printing beyond
the end of the array.
How can I determine how many variable-length lines are in the array?
The only way I can think of is to modify readfile so it can be called
as:
int numlines=read_file("filename.txt", lines);
Is there another/better way?
Thanks for any tips,
Pakt.