我遇到的問題是使用標準輸入從文件中讀取多行整數。這些文件看起來像:C從文件讀取多行文件
123
423
235
523
..etc
我此刻的代碼是:
/*
* Read in the initial puzzle configuration.
* Each line is 4 characters long:
* Row as a character '0' .. '9'
* Column as character '0' .. '9'
* Digit as character '0' .. '9'
* Terminating newline.
* Exits with an error message if there are syntactic
* or semantic errors with any configuration line.
*/
void configure(FILE *puzzle_file) {
int row;
int column;
int value;
while((fscanf(puzzle_file, "%i%i%i\n", row, column, value)) != EOF){
fscanf(puzzle_file, "%i%i%i\n", row, column, value);
puzzle[row][column] = value;
fixed[row][column] = 1;
}
}
我試圖用的fscanf因爲該文件的格式是否正確(如根據功能配置上面的評論)但我無法得到它的工作。
如果有不同的,更簡單的方法來解決這個可以看到的解決方案。
語言:C
編輯:
在編譯錯誤:
[email protected]:~/350/sudoku$ make
gcc -c puzzle.c
puzzle.c: In function ‘configure’:
puzzle.c:95: warning: format ‘%i’ expects type ‘int *’, but argument 3 has type ‘int’
puzzle.c:95: warning: format ‘%i’ expects type ‘int *’, but argument 4 has type ‘int’
puzzle.c:95: warning: format ‘%i’ expects type ‘int *’, but argument 5 has type ‘int’
puzzle.c:96: warning: format ‘%i’ expects type ‘int *’, but argument 3 has type ‘int’
puzzle.c:96: warning: format ‘%i’ expects type ‘int *’, but argument 4 has type ‘int’
puzzle.c:96: warning: format ‘%i’ expects type ‘int *’, but argument 5 has type ‘int’
gcc -o sudoku main.o puzzle.o arguments.o
在我的測試誤差的運行:
[email protected]:~/350/sudoku$ make test_l2
./sudoku -e p+s/good_puzzle.txt < p+s/script_good_quit.txt
/bin/sh: line 1: 9143 Segmentation fault ./sudoku -e p+s/good_puzzle.txt < p+s/script_good_quit.txt
make: *** [good_configured] Error 139
這將無法編譯爲拼圖沒有定義 - 你的代碼如何不工作 - 什麼是錯誤信息或其他可見行爲? – Mark 2011-03-23 16:44:24
我將編譯和測試錯誤添加到問題中。 – DestroyerDust 2011-03-23 16:48:23