只要“主要”变量只有一个单词,该程序就会工作。例如,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-从输入与 - 空间字符) –