Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 713987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:01:27+00:00 2026-05-14T05:01:27+00:00

void spriteput(int x,int y, int stype) { char sprite1[5]=OOOO; char sprite2[5]=OOOO; char sprite3[5]=OOOO; char

  • 0
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:01:27+00:00Added an answer on May 14, 2026 at 5:01 am

    Your declarations inside the if statement 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

    if (stype == 1)
    {
        sprite1[0] = ' ';
        sprite1[3] = ' ';
        // ...
    

    Or you could use a function like strcpy to 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void expand_combinations(const char *remaining_string, string const & s, int rema in_depth) { if(remain_depth==0) {
void reverse_string(char* string, int str_size) { char tmp; int i = 0; int j
void reverse(char *str){ int i,j; char temp; for(i=0,j=strlen(str)-1; i<j; i++, j--){ temp = *(str
void distinct (void) { char sent; int n1, n2, n3, n4, n5, n6, n7;
void main(){ int i,k; char* p; int j; printf(address of i is %d \naddress
void slice_first_char(char ** string) { *string = &(*string[1]); } int main(int argc, char *
void display(char * str){ printf(%s: Missing file\n, str); } int main(int argc, char **argv)
void gctinp (char *inp, int siz) { puts (Input value: ); fgets (inp, siz,
void foo(char *p) { int i; int len = strlen(p); p = malloc(sizeof(char)*len+2); p[0]
void test() { int buf[1000]; //populate buf foo(buf);//is this correct? Can we pass buf

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.