一般來說 scanf 遇到空白、\t、\n 就會自動中斷:

scanf("%s",str);  // 輸入「hello world」
printf("%s",str); // 輸出「hello」


  scanf 可以自定欲接收的字元,改一下就可以接收空白等字元:

scanf("%[^\n]",str);  // 接收除了 \n 以外的所有字元
printf("%s",str); // 輸出完整的「hello world」

 

arrow
arrow
    全站熱搜

    ASTRUE 發表在 痞客邦 留言(0) 人氣()