cmp命令返回EOF在我的输出,尽管精确匹配,据我所知。

时间:2021-03-09 22:50:07

So I will start by saying this is for a course and I assume the professor won't really care that they are the same if cmp returns something weird. I am attempting to compare the output of my code, named uout, to the correct output, in the file correct0. The problem however is that it returns "cmp: EOF on uout". From a little bit of digging I found that EOF indicates they are the same up to the end of the shorter file with the shorter file being the one named after EOF, so what I gather from this is that they are the same until uout ends short. Problem is however, that it absolutely does NOT end short. When opening both in a text editor and manually checking spaces, line and column numbers, etc. everything was an EXACT match.

所以我先说这是一门课程,我假设教授不会真正关心,如果cmp返回一些奇怪的东西,它们是一样的。我正在尝试将我的代码的输出,命名为uout,输出到正确的输出,在文件更正。但问题是它返回“cmp: EOF在uout”。从一点点的挖掘中我发现,EOF表示它们与较短的文件的结尾是相同的,而较短的文件是以EOF命名的,所以我从这里收集到的是它们是相同的,直到uout结束。然而问题是,它绝对不会结束。当在文本编辑器中打开并手动检查空格、行号和列号等时,一切都是完全匹配的。

To illustrate my point here are the files copied directly using ctrl-a + ctrl-v:

为了说明我的观点,这里是直接使用ctrl-a + ctrl-v复制的文件:

correct0 http://pastebin.com/Bx7SM7rA

correct0 http://pastebin.com/Bx7SM7rA

uout http://pastebin.com/epMFtFpM

uout http://pastebin.com/epMFtFpM

If anyone knows what is going wrong and can explain it simply I would appreciate it. I have checked multiple times and can't find anything wrong with it. Maybe it is something simple and I just can't see it, but everything I have seen so far seems to suggest that the files are the same up until the "shorter one" ends, and oddly even if i switch my execution from

如果有人知道哪里出了问题,可以简单地解释一下,我会很感激的。我已经检查过很多次了,没有发现有什么问题。也许它很简单,我只是看不出来,但到目前为止,我所看到的一切似乎都表明,文件在“短”结束之前都是相同的,而且奇怪的是,即使我改变了执行。

cmp correct0 uout

to

cmp uout correct0

both instances end up returning

这两个实例最终都会返回。

cmp: EOF on uout

1 个解决方案

#1


4  

The files you uploaded are same. It can be a line ending problem. DOS/Windows uses "\r\n" as a line ending, but Unix/Linux uses just a "\n".

你上传的文件是一样的。它可以是一个行结束问题。DOS/Windows使用“\r\n”作为一个行结束,但是Unix/Linux只使用一个“\n”。

The best utility on Linux machine for checking what your problem is, is "od" (octal dump) or any other command for showing files in their binary format. That is:

用于检查您的问题的Linux机器上的最佳实用程序是“od”(octal转储)或任何其他命令,以显示其二进制格式的文件。那就是:

$ od -c uout.txt 
0000000   E   n   t   e   r       t   h   e       n   u   m   b   e   r
0000020   s       f   r   o   m       1       t   o       1   6       i
0000040   n       a   n   y       o   r   d   e   r   ,       s   e   p
0000060   a   r   a   t   e   d       b   y       s   p   a   c   e   s
0000100   :  \r  \n  \r  \n       1   6           3           2       1
0000120   3  \r  \n           5       1   0       1   1           8  \r
0000140  \n           9           6           7       1   2  \r  \n    
0000160       4       1   5       1   4           1  \r  \n  \r  \n   R
0000200   o   w       s   u   m   s   :       3   4       3   4       3
0000220   4       3   4  \r  \n   C   o   l   u   m   n       s   u   m
0000240   s   :       3   4       3   4       3   4       3   4  \r  \n
0000260   D   i   a   g   o   n   a   l       s   u   m   s   :       3
0000300   4       3   4  \r  \n  \r  \n   T   h   e       m   a   t   r
0000320   i   x       i   s       a       m   a   g   i   c       s   q
0000340   u   a   r   e
0000344

As you can see, here the line endings are \r\n. Since you have opened and copy pasted the files, this represents your machines preferences and not the actual fiels line ending. Also you can try dos2unix utility to convert line endings.

正如你所看到的,这里的行尾是\r\n。由于您已经打开并复制粘贴了文件,所以这表示您的机器首选项,而不是实际的fiels行结束。您还可以尝试dos2unix实用程序来转换行结束。

#1


4  

The files you uploaded are same. It can be a line ending problem. DOS/Windows uses "\r\n" as a line ending, but Unix/Linux uses just a "\n".

你上传的文件是一样的。它可以是一个行结束问题。DOS/Windows使用“\r\n”作为一个行结束,但是Unix/Linux只使用一个“\n”。

The best utility on Linux machine for checking what your problem is, is "od" (octal dump) or any other command for showing files in their binary format. That is:

用于检查您的问题的Linux机器上的最佳实用程序是“od”(octal转储)或任何其他命令,以显示其二进制格式的文件。那就是:

$ od -c uout.txt 
0000000   E   n   t   e   r       t   h   e       n   u   m   b   e   r
0000020   s       f   r   o   m       1       t   o       1   6       i
0000040   n       a   n   y       o   r   d   e   r   ,       s   e   p
0000060   a   r   a   t   e   d       b   y       s   p   a   c   e   s
0000100   :  \r  \n  \r  \n       1   6           3           2       1
0000120   3  \r  \n           5       1   0       1   1           8  \r
0000140  \n           9           6           7       1   2  \r  \n    
0000160       4       1   5       1   4           1  \r  \n  \r  \n   R
0000200   o   w       s   u   m   s   :       3   4       3   4       3
0000220   4       3   4  \r  \n   C   o   l   u   m   n       s   u   m
0000240   s   :       3   4       3   4       3   4       3   4  \r  \n
0000260   D   i   a   g   o   n   a   l       s   u   m   s   :       3
0000300   4       3   4  \r  \n  \r  \n   T   h   e       m   a   t   r
0000320   i   x       i   s       a       m   a   g   i   c       s   q
0000340   u   a   r   e
0000344

As you can see, here the line endings are \r\n. Since you have opened and copy pasted the files, this represents your machines preferences and not the actual fiels line ending. Also you can try dos2unix utility to convert line endings.

正如你所看到的,这里的行尾是\r\n。由于您已经打开并复制粘贴了文件,所以这表示您的机器首选项,而不是实际的fiels行结束。您还可以尝试dos2unix实用程序来转换行结束。