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 - C Tutorial
From the course: Advanced C Programming: Optimize Performance and Efficiency
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Sort an array6m 39s
-
(Locked)
Challenge: Sort a string24s
-
(Locked)
Solution: Sort a string1m 28s
-
(Locked)
Work with arrays and functions3m 21s
-
(Locked)
Challenge: An array-modification function24s
-
(Locked)
Solution: An array-modification function1m 16s
-
(Locked)
Send a structure to a function4m
-
(Locked)
Challenge: Create a structure function27s
-
(Locked)
Solution: Create a structure function1m 20s
-
(Locked)
Build an array of structures3m 36s
-
(Locked)
Challenge: Sort an array of structures32s
-
(Locked)
Solution: Sort an array of structures1m 7s
-
(Locked)
-
-