by Dinesh Thakur Category: Function and Pointer

We may often require a horizontal line of a dash, underline or some other character to be printed, particularly when printing results in a tabular format. Consider a situation in which we require a line containing a fixed number of a specific character (e.g., 65 dash characters) to be printed several times.


The function print_65_dash_line does not have any parameter and it does not return any value. The body of the function first declares index variable i. Then it prints a line containing 65 dashes followed by a newline character. Although we could have used a single printf statement to print the desired line of dashes, the for loop allows us to quickly change the line length. However, if we require lines of different lengths to be printed, it is better to pass the line length as a parameter to this function.

We can define a function to print such a line, as shown below:

#include <stdio.h>

void main ()


      char i;


      printf("Print a Line of a given character:\n");







      int i;

      for (i=0; i < 65; i++)

           putchar ( '-' ) ;

               putchar ('\n') ;

               return 0;

        C Program Function to Print a Line of a given character

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles