使用 fscanf() 读取文本文件时出错
Error when reading text file with fscanf()
我正在尝试使用 fscanf()
从文本文件中读取,我得到的输出是:
Process finished with exit code -1073741819 (0xC0000005)
第一次调用 fscanf()
时发生崩溃。这是我的代码:
int i=0;
FILE * trafficFile;
trafficFile = fopen("../trafficCount.txt","r");
if (trafficFile == NULL){
printf("Could not open traffic file\n");
}
int n = 30;
fscanf(trafficFile,"%d",n);
printf("%d",n);
for (i = 0; i < n; i++){
int temp = 0;
int temp2 = 0;
fscanf(trafficFile, "%d %d", temp, temp2);
printf("%d %d\n", temp, temp2);
}
fclose(trafficFile);
感谢任何帮助。
需要将整型变量的地址传入fscanf()
fscanf(trafficFile, "%d", &n);
fscanf(trafficFile, "%d %d", &temp, &temp2);
我正在尝试使用 fscanf()
从文本文件中读取,我得到的输出是:
Process finished with exit code -1073741819 (0xC0000005)
第一次调用 fscanf()
时发生崩溃。这是我的代码:
int i=0;
FILE * trafficFile;
trafficFile = fopen("../trafficCount.txt","r");
if (trafficFile == NULL){
printf("Could not open traffic file\n");
}
int n = 30;
fscanf(trafficFile,"%d",n);
printf("%d",n);
for (i = 0; i < n; i++){
int temp = 0;
int temp2 = 0;
fscanf(trafficFile, "%d %d", temp, temp2);
printf("%d %d\n", temp, temp2);
}
fclose(trafficFile);
感谢任何帮助。
需要将整型变量的地址传入fscanf()
fscanf(trafficFile, "%d", &n);
fscanf(trafficFile, "%d %d", &temp, &temp2);