C 错误:文件是为不受支持的文件格式生成的,该文件格式不是要链接的体系结构(x86_64)

C 错误:文件是为不受支持的文件格式生成的,该文件格式不是要链接的体系结构(x86_64),c,macos,gcc,terminal,C,Macos,Gcc,Terminal,嗨,我知道关于这个问题有很多问题,但我似乎一个都不懂。我只是有一个简单的代码,读取一个文本文件并将其打印到屏幕上(只是为了检查它是否做了我希望它做的事情)。然后关闭流 这是我的代码: int table[4][4]; static char INFILE[BUFSIZ]; int j = 0; static void trim_line(char linecharacter[]) { int i = 0; int linenumber = 1; // LOOP UN

嗨,我知道关于这个问题有很多问题,但我似乎一个都不懂。我只是有一个简单的代码,读取一个文本文件并将其打印到屏幕上(只是为了检查它是否做了我希望它做的事情)。然后关闭流

这是我的代码:

int table[4][4];
static char INFILE[BUFSIZ];

int j = 0;
static void trim_line(char linecharacter[])
{
    int i = 0;
    int linenumber = 1;

    //  LOOP UNTIL WE REACH THE END OF line
    while(linecharacter[i] != '\0')
    {

        //  CHECK FOR CARRIAGE-RETURN OR NEWLINE
        if( (linecharacter[i] == '\r' || linecharacter[i] == '\n') && linenumber < 3 )
        {
            linenumber++; //increment the line number
            linecharacter[i] = '\0'; // overwrite with nul-byte
            break;          // leave the loop early
        }

        if( linenumber >= 3 && linenumber <=6 )
        {
             table[j][i] = linecharacter[i]; // insert int into array
                 printf("%c", linecharacter[i]); // check lines //error checking statement 
             i = i+1;            // iterate through character array
        }

        if( linenumber > 6)
        {
        // yet to be written
        }
    }
        printf("_\n");
}

void readinfile()
{
    FILE    *infile = fopen(INFILE, "r");
    // ENSURE THAT OPENING FILE HAS BEEN SUCCESSFUL
    if(infile == NULL) {
        printf("cannot open infile '%s'\n", INFILE);
        exit(EXIT_FAILURE);
    }
    // team != NULL
    char linecharacter[BUFSIZ];
    while( fgets(linecharacter, sizeof linecharacter, infile) !=NULL)
    {
        trim_line(linecharacter);
        j++;
    }
    //ENSURE THAT WE ONLY CLOSE FILES THAT ARE OPEN
    if(infile != NULL)
    {
        fclose(infile);
    }

}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        printf("Failure to enter required arguments %d \n", argc);
        exit(EXIT_FAILURE);
    }
    strcpy(INFILE, argv[1]);
    readinfile();
}
我得到这个错误:

ld: warning: ignoring file ThreesInput.txt, file was built for unsupported file format ( 0x33 0x30 0x30 0x20 0x70 0x69 0x65 0x63 0x65 0x73 0x3B 0x20 0x31 0x32 0x30 0x2E ) which is not the architecture being linked (x86_64): ThreesInput.txt

如果有人能告诉我发生了什么,以及如何修复这个错误,那就太好了。谢谢。

您试图将程序的输入文件传递给gcc,这让编译器/链接器感到困惑。您需要首先将程序源代码编译为可执行文件,然后使用输入文件运行可执行文件:

$ gcc -Wall Player.c           # compile Player.c source code to a.out executable
$ ./a.out ThreesInput.txt      # run a.out executable with input file ThreesInput.txt

为什么要在gcc命令行中包含数据文件的名称???您需要将其传递给您的程序,而不是gcc。您是否从pdf复制粘贴了任何内容?当然。非常感谢。我知道两年没有C,我一定做错了什么。
$ gcc -Wall Player.c           # compile Player.c source code to a.out executable
$ ./a.out ThreesInput.txt      # run a.out executable with input file ThreesInput.txt