Name: Anonymous 2011-08-23 5:08
Hi guys, i just started learning c, so i'm pretty much a noob. I was wondering i my code (which actually works) is messed, and things could have been done better
here it is:
#include <stdio.h>
main()
{
typedef struct giocatore {char player_name[30];} player;
int o;
printf("Inserire il numero di giocatori:");
scanf("%d", &o);
player no_player[o];
if (o == 1)
printf("Avete scelto la modalità giocatore singolo\n");
else if ( o >= 1)
printf("Avete scelto la modalità a %d giocatori\n", o);
else
printf("inserire un valore corretto\n");
int i, e = 0;
for(i = 1; i <= o; i++, e++){
printf("Inserire il nome del giocatore %d:", i);
scanf("%s", &no_player[e].player_name);
};
for(i = 0, e = 1; i < o; i++, e++){
printf("Giocatore %d: %s\n",e , no_player[i].player_name);
};
}
here it is:
#include <stdio.h>
main()
{
typedef struct giocatore {char player_name[30];} player;
int o;
printf("Inserire il numero di giocatori:");
scanf("%d", &o);
player no_player[o];
if (o == 1)
printf("Avete scelto la modalità giocatore singolo\n");
else if ( o >= 1)
printf("Avete scelto la modalità a %d giocatori\n", o);
else
printf("inserire un valore corretto\n");
int i, e = 0;
for(i = 1; i <= o; i++, e++){
printf("Inserire il nome del giocatore %d:", i);
scanf("%s", &no_player[e].player_name);
};
for(i = 0, e = 1; i < o; i++, e++){
printf("Giocatore %d: %s\n",e , no_player[i].player_name);
};
}