Trying to write a very simple function that boxes in a hello world print out. I have been stuck here for hours now and would appreciate some help as the frustration is killing me.

The print out should look like this.
//////////////////////
/ Hello World /
/ Hello World /
//////////////////////

This is my current code

#include <stdio.h>

void print_hello(int n);
void print_char(int *);

void main()
{
 print_hello(10);
 print_hello(5);
 print_char(1); 
}

void print_hello(int n, int *)
{
  int i;
  int j; 
    for(i=1 ; i<=n ; i++)
 {
	  printf("Hello World\n");
       printf("\n\n"); 
	}
   for (int j = 1; j<=i ; j++)
   {
 printf ("*");
   }
 }
}

If this will not take you long, please help as I have been here for hours, and would like to move on now.

>>void print_hello(int n, int *)
What is that second parameter for?

All that is doing is printing one line of * below the text. What about above the text and on each side?

****************
** Hello World ***
****************

This is how to do it

  1. Print the top line
  2. Print two *, then the text, then the last two stars, such as printf("**HelloWorld**\n");
  3. Print the last line

You can not do that all in one big loop.

I had to add a second parameter to meet the criteria of the tutorial I was doing, here is the brief:

Modify the print_hello function of Lecture 4a to have an additional character
parameter. The hello's should be boxed in by the character parameter supplied. For
example, if the number of hellos required is two and the "box" character is '/', the
output should look something like this :-

So from my understanding, that is what I had to do, sorry if this is incorrect, but I'm just trying anything now at this stage .

Oh I see. You need to make it like this: void print_hello(int n, int ch); and use the variable ch instead of hard-coded stars. That would make the print statement in my previous post like this: printf("%c%cHello World%c%c", ch,ch,ch,ch); where each %c tells printf() to get the character from the parameter.

You also need to change the function prototype at the beginning of your program.

Please post your question(s) here. I will not respond to PM.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.