只要「主要」變量只有一個單詞,該程序就會工作。例如,CIS是有效的輸入,但計算機信息系統不是。我該如何解決?如何在scanf字符串中包含空格?
#include<stdio.h>
int main()
{
char major [51];
int classes;
printf("What is your major? ");
scanf("%50s", major);
printf("How many classes are you taking this semester? ");
scanf("%d", &classes);
printf("Your major is %s and you are taking %d classes this semester.\n", major, classes);
}
重複的問題:http://stackoverflow.com/q/6282198/2777099 –
可能重複[從輸入讀取字符串與空格字符?](http://stackoverflow.com/questions/6282198/reading-string-從輸入與 - 空間字符) –