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

Solution: Writing a function - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

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.

Contents