c语言连续输入多个字符怎么弄,c语言中的连续输入问题

本文讨论了C语言中遇到的连续输入问题,特别是涉及scanf函数时如何处理输入的换行符导致的错误。分析了错误原因,即输入不匹配及缓冲区中的换行符残留,并提供了解决方案,强调了保持输入与程序指定格式一致以及使用fflush(stdin)清理缓冲区的重要性。
摘要由CSDN通过智能技术生成

(这个是我写的,我觉得博文搬家有点麻烦,然后就复制粘贴过来了。)

1.具体问题(问题的解答还有待进一步的完善)

(1) 完整代码:

#include "stdio.h"

struct date

{

int month;

int year;

int day;

};

struct student

{

int num;

char name[16];

struct date birthday;

};

void main()

{

struct student student1;

printf("please input the data of the student\n");

printf("num \tname \n");

scanf("num is %d,name is %s",&student1.num,student1.name);

//getchar();

fflush(stdin);

printf("put into the birthday\n");

printf("the day \t the month \t the year\n");

scanf("%d%d%d",&(student1.birthday.day),&(student1.birthday.month),&(student1.birthday.year));

printf("the num is %d ,and

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值