为什么玩家 1 的名字没有包含在下面的代码中?

问题描述

问题是获取游戏中的玩家总数,然后使用gets()函数获取他们的名字!!

我想知道为什么玩家 1 的名字没有使用 get() 函数接收以下代码

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>

struct node{
char name[30];
struct node *next;
};
struct node *header;

int main()
{
    int players,i;
    header=NULL;
    printf("Enter the number of players: ");
    scanf("%d",&players);
    for(i=1;i<=players;i++)
    {
        struct node *new_node,*ptr;
        char p[30];
        new_node=(struct node *)malloc(sizeof(struct node));
        printf("Enter the name of player %d: ",i);
        gets(p);
        strcpy(new_node->name,p);
        puts(new_node->name);
            
    }
    
return 0;    
    
} 
 

解决方法

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

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

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