example-2.3.c
example-2.3.c · 1.5 KB
From the archive c_pointers_examples.tar.gz
Download the archive « Back to the archive contents
#include <stdio.h> //| #include <stdio.h>
//|
struct player { //| struct player {
int current_hp; //| int current_hp;
int max_hp; //| int max_hp;
}; //| }
//|
void new_player( struct player *pl, //| int main()
int chp, int mhp ) //| {
{ //| int chp = 20;
if ( chp > mhp ) //| int mhp = 500;
chp = mhp; //| struct player plyr;
(*pl).current_hp = chp; //|
(*pl).max_hp = mhp; //| if ( chp > mhp )
return; //| chp = mhp;
} //| plyr.chp = chp;
//| plyr.mhp = mhp;
int main() //| return 0;
{ //| }
struct player plyr; //|
//|
new_player( &plyr, 20, 500 ); //|
/********************************* //|
* Uncomment the following lines * //|
* to see if new_players works * //|
*********************************/ //|
//printf("Player has %d/%d hp.\n\r", //|
// plyr.current_hp,plyr.max_hp); //|
return 0; //|
} //|