From the course: Complete Guide to C Programming Foundations

Unlock the full course today

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

Solution: Passing values

Solution: Passing values

(upbeat music) - [Narrator] For my solution, the line function requires two arguments, as seen by the function call here, all coded appropriately. The function returns no value, so it's void. It needs an integer value, which I've named length and a character value, C. The function needs a loop to repeat length times. Now, I could create another variable to use as the loop's condition, but instead, I'll just write the for loop like this. No initiation is needed as the value of length is already set, as long as it's greater than zero, decrement length for each iteration of the loop, the sole looping statement outputs the character past, C. Then I'll add a new line output to wrap it up. Make sure you have that closing brace in there. The line function is written first, so I don't need to prototype it. Run to test. There's the line. The beauty of functions like this is that you can specify a line of any length or character. Just set the proper arguments here and the function does the…

Contents