void spriteput(int x,int y, int stype)
{
char sprite1[5]="OOOO";
char sprite2[5]="OOOO";
char sprite3[5]="OOOO";
char sprite4[5]="OOOO";
if (stype == 1)
{
char sprite1[5] = " OO ";
char sprite2[5] = "OOOO";
char sprite3[5] = "OOOO";
char sprite4[5] = " OO ";
mvprintw(2,y,"%s \n",sprite1);
}
mvprintw(x+1,y,"%s \n",sprite2);
mvprintw(x+2,y,"%s \n",sprite3);
mvprintw(x+3,y,"%s \n",sprite4);
}
If I’m correct that block of code should print out on a NCURSES screen
OO
OOOO
OOOO
OO
Instead however, it prints out the default text (the first char statements). Can anyone tell me why this is? The printw statement inside the If-block prints out the proper text, so it’s being assigned correctly. Thank you in advance.
Your declarations inside the
ifstatement are shadowing the declarations outside it; once the if-statement exits, those shadowed declarations are out of scope and gone forever.To work around this, you could do something like
Or you could use a function like
strcpyto accomplish the same thing.This is a situation where compiling with full warnings turned on would have shown you the error without needing to post here, by the way.