从ncurses中读取文本文件中的单个数字

问题描述 投票:0回答:1

我有一个文本文件,其中填充了数字,它们之间没有空格,每行中的位数相同(实际上是ASCII图像)。我需要将每个数字(0-9)读入ncurses的二维数组中,稍后再将其打印到窗口中以重现ASCII图像。 “ scanw”不适用于我,但getch()也不适用。我该如何进行这项工作?

这是代码的相关部分:

int aboutArray[LINES][COLS];

FILE *myFile;
myFile = fopen("sample.txt", "r");
if (myFile == NULL) {
    wprintw(aboutWin, "Failure to open file");
    return(1);
}

//read file into array
for (i = 0; i < LINES; i++) {
    for (j = 0; j < COLS; j++) {
        scanw(myFile, "%1d", &aboutArray[i][j]);
    }
}
fclose(myFile);

for (i = 0; i < LINES; i++) {
    for (j = 0; j < COLS; j++) {
        wprintw(aboutWin, 0, 0, "%1d", aboutArray[i][j]);
    }
}
arrays file text ncurses
1个回答
0
投票

scanw不从scanw读取;它从FILE读取。

使用FILE

© www.soinside.com 2019 - 2024. All rights reserved.