一般來說 scanf 遇到空白、\t、\n 就會自動中斷: scanf("%s",str); // 輸入「hello world」printf("%s",str); // 輸出「hello」 scanf 可以自定欲接收的字元,改一下就可以接收空白等字元: scanf("%[^\n]",str); // 接收除了 \n 以外的所有字元printf("%s",str); // 輸出完整的「hello world」