/** * structs2.c * * Tests structs, dynamic allocation, and arg passing (in class example). * * Compile: gcc -g -Wall -o structs2 structs2.c * Run: ./structs2 */ #include #include struct something_great { int num; char name[100]; }; /* <- dont' forget the semicolon */ void func(struct something_great s) { printf("num = %d, name = %s\n", s.num, s.name); } void func2(struct something_great *s) { printf("num = %d, name = %s\n", s->num, s->name); strcpy(s->name, "hi"); s->num = 99; } int main(void) { struct something_great greatest = { 0 }; greatest.num = 24; strcpy(greatest.name, "Dennis Ritchie"); printf("num = %d, name = %s\n", greatest.num, greatest.name); func(greatest); func2(&greatest); printf("num = %d, name = %s\n", greatest.num, greatest.name); return 0; }