【发布时间】:2014-12-24 01:01:55
【问题描述】:
我想像下面那样解析十六进制网格,并将字母或空格放入char hexadoku[16][16];
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| h | p m o | i k | n f l |
+ + + + + + + + + + + + + + + + +
.....
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
验证第 1 行和第 3 行很容易,只需像 scanf 一样(1 - 错误输入,0 - ok):
(scanf("+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+%c", &n) != 1 || n != '\n')
(scanf("+ + + + + + + + + + + + + + + + +%c", &n) != 1 || n != '\n');
但是当我尝试阅读第二行时:
scanf("| %c %c %c %c | %c %c %c %c | %c %c %c %c | %c %c %c %c |\n",
&hexadoku[line][0], &hexadoku[line][1], &hexadoku[line][2], &hexadoku[line][3],
&hexadoku[line][4], &hexadoku[line][5], &hexadoku[line][6], &hexadoku[line][7],
&hexadoku[line][8], &hexadoku[line][9], &hexadoku[line][10], &hexadoku[line][11],
&hexadoku[line][12], &hexadoku[line][13], &hexadoku[line][14], &hexadoku[line][15])
Scanf 失败,写入 16 个字符中的 4 个。 如果我用空格替换空白字符并将其写回网格:
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| h | p m | | | |
+ + + + + + + + + + + + + + + + +
...
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
知道我的代码有什么问题以及如何解析十六进制网格吗?
【问题讨论】:
-
你确定空字符是空格吗?我的意思是:可能其中一些是制表符 '\t' 字符?
-
是的。我刚刚在十六进制编辑器中检查了输入文件。
标签: c