我遇到的问题是使用标准输入从文件中读取多行整数。这些文件看起来像: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