通过读取函数读取编译器中的 .asm 文件



我正在尝试编写一个能够读取 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,但没有定义其他两个。

最新更新