Created
February 4, 2015 21:34
-
-
Save timw4mail/27384ab1b4e42b1d4ea4 to your computer and use it in GitHub Desktop.
Learn C the hard way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
typedef struct { | |
char *name; | |
int age; | |
int height; | |
int weight; | |
} Person; | |
Person Person_create(char *name, int age, int height, int weight) | |
{ | |
Person who; | |
who.name = name; | |
who.age = age; | |
who.height = height; | |
who.weight = weight; | |
return who; | |
} | |
void Person_print(Person who) | |
{ | |
printf("Name: %s\n", who.name); | |
printf("\tAge: %d\n", who.age); | |
printf("\tHeight: %d\n", who.height); | |
printf("\tWeight: %d\n", who.weight); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
// make two people structures | |
Person joe = Person_create("Joe Alex", 32, 64, 140); | |
Person frank = Person_create("Frank Blank", 20, 72, 180); | |
// print them out and where they are in memory | |
//printf("Joe is at memory location %p:\n", *joe); | |
Person_print(joe); | |
//printf("Frank is at memory location %p:\n", *frank); | |
Person_print(frank); | |
// make everyone age 20 years and print them again | |
joe.age += 20; | |
joe.height -= 2; | |
joe.weight += 40; | |
Person_print(joe); | |
frank.age += 20; | |
frank.weight +=20; | |
Person_print(frank); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment