小编Fab*_*iro的帖子

不同顺序的相同声明在gcc中产生不同的结果

问题在第7行: int ret=3, x, y;

如果我首先声明y(如第8行),结果将是不同的

在我的电脑上现在只打印Y值,声明中的这个更改只打印X的值

Makefile文件

gcc -g -o open_file_test open_file_test.c;
./pen_file_test input
Run Code Online (Sandbox Code Playgroud)

码:

#include <stdio.h>
#include <stdlib.h>

int worldsize = 0;

int main(int argc, char const *argv[]){
    int ret=3, x, y;
    //int ret=3, y, x;
    char chr;
    int teste;

    FILE * inputFile;
    inputFile = fopen(argv[1],"r");
    teste = fscanf(inputFile,"%d", &worldsize);
    printf("Tamanho: %d\n", worldsize);

    while(1){
        ret=fscanf(inputFile,"%d %d %s\n", &x, &y, &chr);
        if(ret != 3)
            break;
        printf("x: %d  y: %d\n", x, y);
    }
    printf("End File :D\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输入文件 …

c file-io

2
推荐指数
1
解决办法
56
查看次数

标签 统计

c ×1

file-io ×1