2016-07-21 10:22:47 -07:00

44 lines
1.0 KiB
C

#include <stdio.h>
int gain(int current, int amount_gained);
void gain_by_pointer(int *current, int amount_gained);
int main(){
struct players{
int life;
int magic;
};
struct players player1;
player1.life = 5;
player1.magic = 0;
printf(" Hi\n player1's life is currently: %d\n", player1.life);
printf(" player1's magic is currently: %d\n", player1.magic);
player1.magic = gain(player1.magic, 5);
player1.life = gain(player1.life, 32);
printf("\n player1's new magic is %d: \n", player1.magic);
printf(" player1's new life is %d: \n", player1.life);
printf(" Adding 1 to both life and magic through pointer magic! \n");
gain_by_pointer(&player1.magic, 1);
gain_by_pointer(&player1.life, 1);
printf("\n Thanks to pointer magic, life is now %d, magic is now, %d\n", player1.life, player1.magic);
}
void gain_by_pointer(int *current, int amount_gained){
*current += amount_gained;
}
int gain(int current, int amount_gained){
int new_current;
new_current = current + amount_gained;
return new_current;
}