【发布时间】:2019-08-07 16:32:31
【问题描述】:
我有一个二进制文件,其大小为 (sizeof(int)+sizeof(char)) 乘以二叉树中的节点数。 int 是存储在每个节点上的数据,char 是到达文件中该部分时执行的操作。 (i 用于插入,d 用于删除)我只需要知道如何将二进制文件转换为文本文件以进行测试。
输出应该是这样的:
10 i
9 i
14 i
12 i
9 d
到目前为止,我的程序如下所示:
void convert(char * input, char * output)
{
FILE * fpin = fopen(input, "rb");
FILE * fpout = fopen(output, "w");
char * oper; // operation (either 'i' or 'd')
int key; // information to be held by a node
while ((fscanf(fpin, "%d%s", &key, oper) == 2) {
fprintf(fpout, "%d %s\n", key, oper);
}
fclose(fpin);
fclose(fpout);
}
但是,我收到一条警告说 oper 可能未初始化。
【问题讨论】: