看了一下楼主貼的代码, 对于fgets函数来说,是读取一行包括行尾的换行符'\n',若要两行比较的话,要将'\n'去掉换成'\0’才算是一个完整的字符串
Linux 下 man 配置对 fgets 的说明
fgets() reads in at most one less than size characters from stream and stores them into the
buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it
is stored into the buffer. A terminating null byte ('\0') is stored after the last charac‐
ter in the buffer.
Linux 下 man 配置对 fgets 的说明
fgets() reads in at most one less than size characters from stream and stores them into the
buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it
is stored into the buffer. A terminating null byte ('\0') is stored after the last charac‐
ter in the buffer.