【发布时间】:2020-04-29 07:20:43
【问题描述】:
我需要使用 C 从 CSV 文件中读取带有某种矩阵的文件(矩阵列和行的数量可能每次都不同)。 该文件将是这样的:
#,#,#,#,#,#,.,#,.,.,.$
#,.,#,.,.,#,.,#,#,#,#$
#,.,#,.,.,.,.,.,.,#,#$
#,.,#,.,.,#,#,#,#,#,#$
#,.,.,#,.,.,.,.,.,.,#$
#,.,.,.,#,.,#,#,.,.,#$
#,.,.,.,.,#,.,.,.,.,#$
#,.,.,.,.,#,.,.,.,.,#$
#,.,.,.,.,.,.,.,.,.,#$
#,#,#,#,#,#,#,#,#,.,#$
我需要读取文件并将其保存到二维数组中,以便能够遍历它并使用 Lee 算法找到走出迷宫的路径。
所以我想做一些类似的事情:
int fd = open (argv[i], O_RDONLY);
while (read(fd, &ch, 1)) {
here should be some for loops to find the number of colums and rows.
}
不幸的是,如果矩阵的高度和宽度未知,我不知道该怎么做。
我正在尝试这样做:
while (read (fd, &ch, 1)) {
for (int i = 0; arr[i] != '\0'; i++) {
for (int j = 0; j != '\n'; j++) {
somehow save the values, number of columns and rows.
}
}
}
但是,行数可能大于列数。 任何帮助将不胜感激
【问题讨论】:
标签: c arrays multidimensional-array