首先,我尝试使用 fopen 函数打开一个文件并使用 fprint 函数打印文件的内容,但它只是将一堆符号打印到终端。
过了一会儿,我意识到它不会将指向流的指针作为参数,并且上述行为是预期的。它正在打印实际的指针值。putc 或 puts 函数似乎也不将指向文件 I/O 流的指针作为参数。
我现在最好的猜测是我必须访问以某种方式创建的缓冲区 fopen 函数!但我不知道如何或是否可能。总而言之,我现在完全陷入困境。
这里的最终目标是从 STDIN 和/或文件获取输入,对文本进行一些处理(例如:小写到大写)并将结果输出到 STDOUT 和/或文件。我想如果我能够得到上述问题的答案,那么它可能有助于实现最终目标。
PS:让我知道这个问题是否可以以任何方式改进。谢谢你。
也许以下代码将有助于更好地理解我要说的内容。
.section .data
o_rdonly:
.ascii "r"
content:
.ascii "Content of the file: %d\n" #This is how I figured what those random symbols were.
.section .bss
.lcomm buffer, 10
.section .text
.globl _start
_start:
movl %esp, %ebp
pushl $o_rdonly
pushl 8(%ebp)
call fopen
##Print the content of the file?##
#pushl %eax #
#call printf #It just prints the actual address of the File I/O pointer.
pushl $0
call exit