簡體   English   中英

在C語言中讀取幾個字符串后如何讀取空格的其余行

[英]How to read rest of line with spaces after reading couple of strings in C

我的輸入如下所示:

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); 
    }
}

也許此鏈接中的示例會有所幫助: http : //www.cplusplus.com/reference/clibrary/cstring/strcmp/

最好提供完整的代碼。

給出的輸入/輸出沒有錯,其余的代碼類似於:

#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); 
     }
   }
 }

因此,無論您遇到什么問題,它們都必須處理您對模式,鍵和數據的定義,或樹插入/搜索的實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM