Answer L31


#include <stdio.h>

void starLine( int n )
{
  int j;
  for ( j=0; j<n; j++ )
    putchar('*');
  putchar('\n');
}

int main()
{
  starLine( 8 );  	
  return 0;
}

Comments: You could also use printf("*") in the above.

If you want to use a command line parameter, do this:

int main()
{
  int stars=0;
  
  if ( argc >= 2 ) stars = atoi( argv[1] );
  starLine( stars );  
. . .

An odd aspect of this program is that the statement putchar('\n') outputs different characters depending your operating system. On windows systems it prints out "carriage return" followed by "line feed." On Unix systems it prints out a single "line feed" character and on older Apple systems it prints out "carriage return".



Back to Puzzle Home