#Meta-Wlp: #Macro: TITLE wlp: Learn C (5) p. 8
Moving the struct to the top of the file will fix this problem. Since the form we are using only serves to define a structre tag, we can place it outside of any function, at the top. Then we can create and use variables of that structure type throughout the file.
#includeDoes this work? #Shuffle: none $PAGE$-A $PAGE$-B Return to Learn C Introduction #: Of course, now that we have been correct, we will be shown the correct way, to reinforce the learning. It is very much according to Correct Psychological Principals Taught in Eduction Departments. #: No, I smell a rat. He's leading us on. #:struct name { char * first ; char * last ; } ; void swapNames( struct name n1, struct name n2 ) { char * temp ; temp = n1.first ; n1.first = n2.last ; n2.last = temp ; } int main(int argc, char * argv) { struct name n1 = { "dylan", "thomas" } ; struct name n2 = { "bob", "danny" } ; swapNames( n1, n2 ) ; printf("%s %s\n", n1.first, n1.last ) ; printf("%s %s\n", n2.first, n2.last ) ; }