example-3.2.c
example-3.2.c · 513 B
From the archive c_pointers_examples.tar.gz
Download the archive « Back to the archive contents
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
struct player {
char name[20];
int hp;
};
int main()
{
struct player *plyr;
plyr = (struct player *) malloc( sizeof(struct player) );
strcpy( plyr->name, "MudByter" );
plyr->hp = 500;
/***********************************
* Uncomment the following line to *
* have look at the player struct *
***********************************/
//printf( "Player %s has %d hp.\n\r", plyr->name, plyr->hp );
free( plyr );
return 0;
}