【发布时间】:2017-04-02 17:13:13
【问题描述】:
#include<stdio.h>
int main()
{
int choice;
char sl[10];
char phn[10];
printf("Enter choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter Student Details: \n\n");
printf("\nEnter serial number: ");
gets(sl);
printf("Roll number: ");
gets(phn);
default:
break;
}
return 0;
}
C 编程:
我在这里使用了 2 个 gets() 函数。第二个正在工作,但第一个不工作。为什么??如何让它发挥作用?
注意:我想将“sl”和“phn”变量作为 char 类型,并且我想使用 gets() 来获取输入。 请有人帮忙....
【问题讨论】:
-
想一想:为
scanf输入的数字,您使用什么键来结束输入?提示:Enter键也将作为换行符放入输入缓冲区。 -
gets很危险且已弃用(并已从 C11 标准中删除)。使用fgets或者getline