我的输入如下所示:
save 001 Some very long string with spaces... after three dots there , is also a comma
在此之后我调用类型:
load 001
它应该给我输出:
Some very long string with spaces... after three dots there , is also a comma
我正在尝试,但似乎没有任何效果,例如:
while ((scanf("%s %s", mode, key)) != EOF) {
if (strcmp(mode, "save") == 0) {
getchar();
fgets(data, 100, stdin);
root = save(root, key, data);
root = balance_RBT(root, blc);
}
if (strcmp(mode, "load") == 0) {
load(root, key);
}
}
最佳答案
给定的输入/输出没有任何问题,代码的其余部分类似于:
#include <stdio.h>
int main()
{
char mode[444], key[333], data[222];
while (1)
while ((scanf("%s %s", mode, key)) != EOF) {
if (strcmp(mode, "save") == 0) {
getchar();
fgets(data, 100, stdin);
printf("SAVE %s %s %s\n",mode,key,data);
//root = save(root, key, data);
//root = balance_RBT(root, blc);
}
if (strcmp(mode, "load") == 0) {
printf("LOAD %s %s\n",mode,key);
// load(root, key);
}
}
}
因此,无论您遇到什么问题,它们都必须处理您对模式、键和数据的定义,或者树插入/搜索的实现。
关于c - 如何在读取 C 中的几个字符串后读取带有空格的行的其余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13430495/