问题在第7行: int ret=3, x, y;
如果我首先声明y(如第8行),结果将是不同的
在我的电脑上现在只打印Y值,声明中的这个更改只打印X的值
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)