c - 通过 read 函数在编译器中读取 .asm 文件

标签 c

我正在尝试用 c 语言编写一个能够读取 .asm 文件的程序。

#include  <stdio.h>

int preprocess_get_line(char label[], char instruction[], FILE* fp);

int main(int argc, char *argv[])
{
    /* Open file and check success */
    char *filename = "helloworld.asm";
    if (argc >1)
    {
        filename = argv[1];
    }
    FILE* inputfile = fopen(filename, "r");
    if(inputfile == NULL)
    {
        fprintf(stderr, "Unable to open \"%s\"\n", filename);
        return 1;
    }
    while (preprocess_get_line(label, instruction, inputfile))
    {
        fprintf("%s: %s", label, instruction);
    }
    return 0;
}

int preprocess_get_line(char label[], char instruction[], FILE* fp)
{
    fgets(str,260, fp);
    while(character != EOF)
    {
        printf("ASCII hex: %2x '%c'\n", (int)character, character);
        character = fgets(inputfile);
    }
    fclose(inputfile); 
} 

这是我编写的代码,但是我的代码中不断收到多个错误。 我在第 19 行遇到的一个特定错误 标签未声明(在此函数中首次使用) 我的理解是我已经声明了该函数(在第 2 行。) 第 19 行又出现一个错误 每个未声明的标识符仅针对其出现的每个函数报告一次 至于这个错误我不太确定问题是什么。

最佳答案

第 19 行未定义 labelinstruction。您定义了 inputfile,但没有定义其他两个。

关于c - 通过 read 函数在编译器中读取 .asm 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35708766/

相关文章:

c - 在文件范围错误处可变修改了 'variable_name'?

c++ - 检查时间是否在 C++ 中的特定时间间隔内?

c - 如何释放结构中的指针?

c - 在 C 编程中,如何将两个头文件和 3 个 c 文件链接到一个可执行文件中?

c - 产生堆栈溢出

c++ - 窗口没有响应 XMoveResizeWindow 请求

c - 如何在 C 中以编程方式实现 'tee'?

c - 未初始化变量的值是由编译器设置的还是由什么设置的?

c - 为什么 C 运行时不调用我的 exit()?

c - C : does GCC follow the C99 spec, 中的链接还是我不了解规范?