From the course: C Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Writing a function - C Tutorial
From the course: C Essential Training
Solution: Writing a function
(bright upbeat music) - Here is my rendition of the solution where I wrote the line function, before the main function. In the function, I use variable A in a loop repeating 40 times. The putchar function outputs the 40 hyphens, and a second putchar function outputs a new line, which keeps the line, on a line by itself, build and run. And there's the output. If your programs output looks like this, you've successfully worked the challenge. In this variation, which is also a correct solution, I wrote the line function after the main function. In this arrangement, the line function must be prototyped which you see here on line three. This solution is also valid and I won't count points off if you came up with it. It's creative. Of course, if you're required to modify the function later, say to generate a line of variable length, then it'll be more work. Still, this solution works. So kudos to you if you came up with it.
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
-
-
-
-
-
-
-
Understanding functions3m 21s
-
(Locked)
Creating a function3m 28s
-
(Locked)
Challenge: Writing a function46s
-
(Locked)
Solution: Writing a function1m 10s
-
(Locked)
Returning a value from a function2m 33s
-
(Locked)
Challenge: Returning a value42s
-
(Locked)
Solution: Returning a value1m 40s
-
(Locked)
Passing arguments to a function1m 52s
-
(Locked)
Challenge: Passing values44s
-
(Locked)
Solution: Passing values1m 22s
-
(Locked)
Using the main() function's arguments3m 30s
-
(Locked)
Retaining values in a function2m 58s
-
(Locked)
Creating recursive functions3m 53s
-
(Locked)
Challenge: Complete the code1m 14s
-
(Locked)
Solution: Complete the code1m 31s
-
-