我使用的变量数量有限,所以我想仅使用一个变量来解决以下问题。可能吗?将三个字完全读入一个字符数组中
char str[100];
// Type three words:
printf("Type three words: ");
scanf("%s %s %s",str,str,str);
printf("You typed in the following words: \"%s\", \"%s\" and \"%s\"\n",str,str,str);
下面的输入提供了以下的输出:
Type three words: car cat cycle
You typed in the following words: "cycle", "cycle" and "cycle"
自上次读出字存储到同一个字符数组的开始这是不是很奇怪。有没有简单的解决方案?
多少个变量是你允许使用?这是家庭作业还是减少变量试图解决一个未阐明的基本问题(例如堆栈溢出)? – simonc