我正在尝试以相反的顺序打印文件。我正在使用数组来保存每行数据。到目前为止,我能够按正常顺序打印每一行。
index 是我指的行数,FuncIndex 是同一件事,但已在函数中再次声明。
file = fopen("../quotes.data","r");
while (NumOfField == 8) {
NumOfField = fscanf(file,"%d,%c,%d,%d,%c,%c,%lf,%lf", "e[index], &roomletter[index], &length[index], &width[index], &paint[index], &ceiling[index], &cost[index], &setup_cost[index]);
index++;
}
index--;
fclose(file);
在函数中:
int FuncIndex;
for (FuncIndex = 0; FuncIndex <= index; FuncIndex++) {
printf("\n%5d %1c %3d %3d %1c %1c %8.2lf %6.2lf", quote[FuncIndex], roomletter[FuncIndex], length[FuncIndex], width[FuncIndex], paint[FuncIndex], ceiling[FuncIndex], cost[FuncIndex], setup_cost[FuncIndex]);
}
现在我尝试将 for 循环更改为:
for (FuncIndex = index; FuncIndex >= 0; FuncIndex--) >
但输出打印为空。尽管当我将 0 更改为任何数字时,相应的行都会被打印出来。
打印的输出是:
Quote Room Length Width Paint Ceiling Cost Setup
===== ==== ====== ===== ===== ======= ======= =====
531 A 10 10 b n 96.00 100.00
531 B 15 15 b n 144.00 0.00
531 C 20 20 b n 192.00 0.00
我希望将此输出反转,如下所示:
Quote Room Length Width Paint Ceiling Cost Setup
===== ==== ====== ===== ===== ======= ======= =====
531 C 20 20 b n 192.00 0.00
531 B 15 15 b n 144.00 0.00
531 A 10 10 b n 96.00 100.00
如果我将输出放在代码部分中,请原谅,因为格式会改变
谢谢。