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

Popular Article