dimanche 1 novembre 2015

What is wrong in the if statement which checks a value from shared memory?

In my code the value of flag is determined by a value in shared memory. when a do a print it says that the value is 1, because it prints '1'. So why does my program not proceed with the code in 'if (flag == "1")'?

char *      shm_addr = (char *) MAP_FAILED;
char *      shm_name = "Print";
int         size = -1;
int         rtnval;
char *      flag;
int         numberToPrint = 0;

size = 32;

while (shm_addr == (char *) MAP_FAILED)
{         
    shm_addr = my_shm_open (shm_name);
}

sscanf (shm_addr, "%s", flag);

printf ("\ndata (@ %#x): '%s'\n", (unsigned int)(intptr_t) shm_addr, flag);

while (numberToPrint != 6)
{
    if (flag == "1")
    {
        numberToPrint += 2;
        printf("%i ", numberToPrint + 2);
        flag = "0";
        sscanf (flag, "%s", shm_addr);
    }                
}

Aucun commentaire:

Enregistrer un commentaire