我正在尝试用 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 行未定义 label
和 instruction
。您定义了 inputfile
,但没有定义其他两个。
关于c - 通过 read 函数在编译器中读取 .asm 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35708766/