the function is supposed to return the length of a line specified by the 2nd argument
but the result is either 0 or the one in the 2nd line whatever n may be:
int line_length(const char *filename, int n)
{
FILE *fp;
int c;
int len = 0;
if ((fp = fopen(filename, "r")) == NULL)
return -1;
while (n > 1)
{
while ((c = fgetc(fp)) != 'n')
/* if (c = EOF) // I removed these couple of lines, otherwise it
return 0; */ // yields always 0 since I THINK EOF always pops
n--; // once the line is finished
}
while ((c = fgetc(fp)) != 'n' && c != EOF)
len++;
return len;
}
I removed these couple of lines, otherwise it
yields always 0 since I THINK EOF always pops
once the line is finished