的问题是在第7行:int ret=3, x, y;
以不同的顺序相同的声明产生的gcc不同的结果
如果我声明的y个第一(如第8行)的结果将是 不同
上我的电脑现在的问题是只打印出Y值,在声明此 变化付印X
的Makefile
gcc -g -o open_file_test open_file_test.c;
./pen_file_test input
只值
CODE:
#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;
}
INPUT_FILE
10 1 0 w 2 1 s 6 9 w 3 7 w 5 0 s 1 5 t 1 5 t 7 5 t 9 7 t 9 3 t 0 0 i
输出
Tamanho: 10 x: 0 y: 0 x: 0 y: 1 x: 0 y: 9 x: 0 y: 7 x: 0 y: 0 x: 0 y: 5 x: 0 y: 5 x: 0 y: 5 x: 0 y: 7 x: 0 y: 3 x: 0 y: 0 End File :D
在我COMPUT呃只读Y,和我同事 上的同一个代码只能读X,而在另一个朋友的电脑上可以正常工作 (读过X和Y),有人能解释一下原因吗?
每种情况下gcc的版本是什么?你确定源文件是否相同? –