程序读取输入字符串并存储在数组中

问题描述

我正在使用gets函数获取输入,但是gets函数会忽略第一个输入命令

#include<stdio.h>
int main(){
    char names[10][10];
    int n,i;

    printf("Enter number of students: ");
    scanf("%d",&n);

    for(i=1; i<=n;i++){
        printf("Enter the name of STUDENT:%d",i);
        gets(names[i]);
    }
    return 0;
}

输出 输入学生人数:5 输入学生的名字:1输入学生的名字:2 //跳过第一个输入后等待我的输入

为什么会这样?我在其他代码编辑器中尝试过,到处都有相同的输出

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)