1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include <stdio.h>
#define NAMES_MAX_LENGTH 19 /* Maximum length of names, not including '\0' */
#define STRINGIFY2( x) #x
#define STRINGIFY(x) STRINGIFY2(x)
static const char names_scan_fmt[]= "%" STRINGIFY(NAMES_MAX_LENGTH) "s";
typedef struct player
{
char prenom[NAMES_MAX_LENGTH + 1]; /* +1 for the '\0' */
char nom[NAMES_MAX_LENGTH + 1];
int age;
} player;
void changement(player *p)
{
printf("quel est ton prenom ?\n");
scanf(names_scan_fmt,p->prenom);
printf("quel est ton nom ?\n");
scanf(names_scan_fmt,p->nom);
printf("quel est ton age ?\n");
while (!scanf("%d",&p->age))
scanf ("%*c");
}
int main(void)
{
player p1,p2;
printf("\n____1er JOUEUR____\n");
changement(&p1);
printf("\n____2eme JOUEUR____\n");
changement(&p2);
printf("Le prenom du 1er joueur est %s,le nom %s et l'age est %d\n",p1.prenom,p1.nom,p1.age);
printf("Le prenom du 2 eme joueur est %s,le nom %s et l'age est %d\n",p2.prenom,p2.nom,p2.age);
return 0;
} |
Partager