C function that counts lines in file

后端 未结 7 2035
广开言路
广开言路 2020-12-06 03:10

When I try to run my program, I get the wrong number of lines printed.

LINES: 0

This is the output although I have five lines in my .txt fi

7条回答
  •  一生所求
    2020-12-06 03:37

    You declare

    int countlines(char *filename)
    

    to take a char * argument.

    You call it like this

    countlines(fp)
    

    passing in a FILE *.

    That is why you get that compile error.

    You probably should change that second line to

    countlines("Test.txt")
    

    since you open the file in countlines

    Your current code is attempting to open the file in two different places.

提交回复
热议问题