【发布时间】:2013-06-10 10:04:21
【问题描述】:
我正在尝试编写一段代码来显示 txt 文件的内容。我只有数字存储在新文件中,每行一个数字 (%d \n)。目前代码如下所示:
movl $0 , 320(%ebp)
#a pre reserved location on the stack for the first number that needs to be cleared first
leal 320(%ebp), %eax #a pre-chosen location for the memory
push %eax
push $dataformat # . asciz "%d \n"
push %ebx #the result from the fopen is stored in ebx
call _fscanf
push 320(%ebp)
push %dataformat
call _printf
但是,除非我将 movl $0 更改为其他值,否则结果仍然为 0。
【问题讨论】:
-
问题是..?
-
如何让它不打印 0 而是打印所需的值。
-
为什么你两次调用
fscanf,第二次没有推送文件句柄?你的意思是打电话给printf? -
是的,我手动输入了它,因为它来自的计算机无法访问堆栈溢出
-
当您将
ebx压入堆栈时,您确定ebx包含有效的文件句柄吗?并且文件的行 exactly 匹配"%d \n"(可能文件中的行结尾略有不同)。你真的应该检查你调用的函数的返回值。