我寫了從命名network.dat我們無法根據
我寫的代碼文件讀取的代碼的讀取文件是
f = fopen("network.dat", "r");
if(f == NULL)
exit(1);
int read, N;
printf("%p\n", f);//output file pointer, included this just to check if file is opened properly
fscanf(f, "%d%d", &N, &read);//error here
cout<<N;
文件被正確打開,我得到的文件指針(49897488
)作爲輸出,但其後面的行是程序停止工作的位置,我沒有得到N
作爲輸出。 請告知是否需要其他細節。 network.dat的內容
10 1
1 6 1.28646
1 7 1.2585
2 9 1.33856
等。我只關注文件中的前兩個數字,即10和1.
變量'N'是什麼? – hmjd
你是如何申報N的? – piokuc
順便說一句,你應該使用'%p'打印'f',而不是'%d'。 – hmjd