0

The question is on taking the total number of players in a game and then taking their names using gets() function !!

I want to know Why the name of player 1 is not taking in the following code using gets() function?

#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;    
    
} 
 
Rigel
  • 1
  • 1

0 Answers0