Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C programming example for a Person struct and typedef (from ECE 2534)
//Example code from class on defining and using a struct //-------myStruct.h--------------- // This would normally be in an include file #ifndef __MYSTRUCT #define __MYSTRUCT typedef struct __Person { char name[30]; char address[50]; int zipcode; } Person; #endif //-------main begins here--------- #include <stdio.h> #include <string.h> // need this for C string functions // helper function to print out Person struct printPerson(Person *myPerson) { printf("Name: %s\n",myPerson->name); printf("Address:\n%s\n",myPerson->address); printf("Zip Code: %5d\n",myPerson->zipcode); } int main(void) { Person student; printf("Example code for a struct, from class.\n\n"); strcpy(student.name,"Joe Nerdy"); strcpy(student.address,"302 Whittemore\nECE Department\nVirginia Tech"); student.zipcode = 87544; printPerson(&student); return 0; }
run
|
edit
|
history
|
help
0
arrays vowles printing
lab 12 v0.1
Bool datatype Operation for GCC
Practice
Project 5 v.02
Project 3 Part 1 v1.1
2017_1117_TARTAGLIA
Practice Problem 7
-Wfloat-conversion
Add c