From the course: Advanced C Programming: Optimize Performance and Efficiency

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Solution: Create a structure function

Solution: Create a structure function

(upbeat music) - [Instructor] For my first solution to the challenge, I chose to use pointers. I wrote three structure functions, allocateStructure, which returns a structure pointer, fillStructure, which gathers input and assigns data to the structure, and showStructure, which displays the structure's values. Much of the information in my solution was shown in an earlier movie. You'll see how the structure pointer member operator is used in lines 41 and 43. With a scanf function, a ampersand is not required at line 41 because the name member is an array, a string. The ampersand operator is required line 43 because the structure member referenced is an integer. Variable age is not a pointer, even though variable P is. So the ampersand is required. Now, if you opted to use a non-pointer solution, then it might look like this. This solution is a bit clunkier. The structure variable is declared at line 20 inside the…

Contents