说句心里话c语言代码
时间: 2023-10-17 14:06:26 浏览: 279
以下是一段C语言代码,用于接收人名和心里话,并输出一句心里话:
#include <stdio.h>
int main() {
char name[20];
char thoughts[50];
// 从控制台接收第一个输入
printf("请输入人名:");
scanf("%s", name);
// 从控制台接收第二个输入
printf("请输入心里话:");
scanf("I[^\n]", thoughts); // 指定最大长度为49,并忽略换行符
// 组成句子并输出
printf("%s, I want to say, %s\n", name, thoughts);
return 0;
}
这段代码中,首先定义了两个字符数组,name用于存储人名,thoughts用于存储心里话。然后通过scanf函数分别从控制台接收人名和心里话的输入。注意,在接收心里话时,使用了格式控制符“I[^\n]”,它的作用是指定最大长度为49,并忽略掉换行符。最后,使用printf函数将人名和心里话组成一句话输出。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)