How to print the shape using different characters instead of *

#include<ncurses.h>
void print_right(int row,int col,int length,char ch);
void print_down(int row,int col,int length,char ch);
void print_left(int row,int col,int length,char ch);
void print_up(int row,int col,int length,char ch);

int main()
{
char ch;
initscr();
while
print_right(11,19,10,ch);
print_down(11,29,6,ch);
print_left(17,29,11,ch);
print_up(17,19,6,ch);
print_up(11,19,6,ch);
print_right(5,19,10,ch);
print_down(5,29,6,ch);

getch();
endwin();
return 0;

}
void print_right(int row,int col,int length,char ch)
{
for(int c=col;c<col+length;c++)
{
move(row,c);
printw("*");
for(int i=0;i<99999999;i++);
refresh();
}
}



void print_down(int row,int col,int length,char ch)
{
for(int r=row;r<row+length;r++)
{
move(r,col);
printw("*");
for(int j=0;j<99999999;j++);
refresh();
}
}


void print_left(int row,int col,int length,char ch)
{
for(int c=col;c<col+length;c++)
{
move(row,2*col-c);
printw("*");
for(int i=0;i<99999999;i++);
refresh();
}
}




void print_up(int row,int col,int length,char ch)
{
for(int r=row;r<row+length;r++)
{
move(2*row-r,col);
printw("*");
for(int j=0;j<99999999;j++);
refresh();
}
}
Replace the * in printw("*"); with some other character.
I'd imagine since all the functions are defined with a char ch you wanted to print whatever you passed into the function, so why not replace all the printw("*"); with printw(ch);? and instead of just passing in an uninitialized variable like you are in your main function, pass in what ever you wanted to print? like print_right(11,19,10,'f');?
drew887 wrote:
and instead of just passing in an uninitialized variable ...

Or initialize it to whatever you want to print. It makes it easier if you want to change the character later you only need to change it at one location.

drew887 wrote:
replace all the printw("*"); with printw(ch);

printw works similar to printf so the first argument should be a string. If you want print the character using printw you can do printw("%c", ch); or you can use addch, addch(ch);.
Well to be honest printw("%c",ch); seems just a little redundant :P
Peter87,drew887, thanks guys i made it using printw("%c",ch);
that is easy rather than pointers
Topic archived. No new replies allowed.