Hello, i'm new to C programming, and i wanted an opinion on this code. I was wondering if it could have been written in a more efficient way. By now the only bug i report is a segfault if i enter a alphanumerical value as the variable "o". Thank you in advance
Code:
#include <stdio.h>
main()
{
typedef struct plr {char player_name[30];} player;
int o;
printf("Insert players number:");
scanf("%d", &o);
player no_player[o];
if (o == 1)
printf("You chose singleplayer\n");
else if ( o >= 1)
printf("You chose %d players mode\n", o);
else
printf("insert a valid value\n");
int i, e = 0;
for(i = 1; i <= o; i++, e++){
printf("insert player %d name:", i);
scanf("%s", &no_player[e].player_name);
};
for(i = 0, e = 1; i < o; i++, e++){
printf("Player %d: %s\n",e , no_player[i].player_name);
};
}