本文介绍了输入使用gets函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面code当我要进入第二个学生或> 2的学生记录..编译器跳过名称输入和输入取类和年龄。什么问题,请帮助我吗?
的#include<&stdio.h中GT;#包括LT&;&CONIO.H GT;学生结构{CHAR名称[16];焦炭类[16];INT年龄;};无效的主要(){结构学生一个[5];的for(int i = 0;我小于5;我++){的printf(\\ n输入名称:);得到(A [I] .Name点);的printf(\\ n进入类:);得到(A [I]。类);的printf(\\ n输入年龄:);scanf函数(%d个,&安培; A [I]。年龄);}残培();}解决方案
问题是很常见。试试这个:
scanf函数(%d个,&安培; A [I]。年龄); ^< ---这个空间会让scanf函数吃剩下的空白有是C常见问题解答这个问题:
- scanf函数隔行
- scanf的问题
- 法拉盛标准输入
辅助Notes:
- 不要使用获得 。使用与fgets 代替。
In Below Code When I want to Enter Record of second student or >2 student .. Compiler skip Name Input and take Input for class and age .. What a problem please help me ?
#include <stdio.h> #include <conio.h> struct Student { char Name[16]; char Class[16]; int age ; }; void main() { struct Student a[5] ; for(int i=0 ; i<5 ; i++) { printf("\n Enter Name :"); gets(a[i].Name); printf("\n Enter Class :"); gets(a[i].Class); printf("\n Enter Age : "); scanf("%d" , & a[i].age); } getch(); }解决方案
The problem is common enough. Try this:
scanf("%d ", &a[i].age); ^ <--- This space will make scanf eat the remaining blanksThere are C FAQs about this:
- Scanf interlace
- Scanf problems
- Flushing stdin
Secondary notes:
- Don't use gets. Use fgets instead.
更多推荐
输入使用gets函数
发布评论