输入使用gets函数

编程入门 行业动态 更新时间:2024-10-25 12:29:18
本文介绍了输入使用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 blanks

There are C FAQs about this:

  • Scanf interlace
  • Scanf problems
  • Flushing stdin

Secondary notes:

  • Don't use gets. Use fgets instead.

更多推荐

输入使用gets函数

本文发布于:2023-11-02 08:06:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551837.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!