1st, IMAO you do not have to post the entire program, just the piece you are trying to fix, as you did.
2nd, as Ancient Dragon said, what's the name of the file? There is nothing in fname[]
3rd, please learn to format your code readably. You need consitant indentation. It's better to use SPACEs, not TABs. And it's good to use extra lines between sections, but not between everything:
int longest(void)
{
char line[BUFSIZE] = {'\0'} ;
int counter=0;
int longest=0;
char fname[128];
FILE *file;
file=fopen(fname,"r");
while (fgets( line, BUFSIZE, file )!=0)
{
counter=strlen(line);
if(counter>longest)
{
longest=counter;
}
}
return longest;
}
Another thing I noticed is a cute trick that you should not use:
nlines += c == '\n';/*Line counter*/
Instead use something easier to read:
if (c == '\n') /*Line counter*/
{
nlines++;
}