I'm trying to put some information into a 2d char array. I'm putting a list of names in stdin that i'm trying to put into an array with a number corresponding to the array of characters(names). For some reason, when I try to print the names, it output some random characters.
#include <stdio.h>
#define NAME_MAX_LENGTH 20
#define NUM_MIN_PLAYERS 2
#define NUM_MAX_PLAYERS 20
struct PlayerList {
unsigned int num_players;
char name[NUM_MAX_PLAYERS][NAME_MAX_LENGTH + 1];
};
int main() {
int num;
char nom[NAME_MAX_LENGTH + 1];
struct PlayerList player;
while(fgets(nom, sizeof nom, stdin) != NULL){
char longueur = 0;
player.name[num++][sizeof nom] = nom;
printf("%d:%s\n", num, player.name[num]);
}
player.num_players = num;
return 0;
};