coracle-databaseoracle-pro-c

Why the control of my PRO*C program doesn't go to the if section?


I am beginner in C and PRO*C and need some help. I have a structure as below:

typedef struct pt_st{
  char (*s_no)[NULL_BIG_SEQ_NO];
  char (*s)[NULL_STORE];
} pt_st;

pt_st pa_st;

Then I have:

   EXEC SQL DECLARE c_st CURSOR FOR
   SELECT 5 as s, nvl(null, 0) as s_no
   FROM dual;

Then I open and fetch the cursor as below:

EXEC SQL OPEN c_st;
EXEC SQL FETCH c_st INTO :pa_st.s, :pa_st.s_no;

afterwards, somewhere in my code I have:

    if (pa_st.s_no[ll_cur_rec] == "0") 
    {
        // do something here, but the control of the program never reaches here!!!  
    }

But the control of the program never goes iside the if condition.

How can I make this work?!


Solution

  • EDIT:

    Updated based on comments.

    s_no is a pointers to an array of char. ( I missed this earlier)

    You are comparing pointer with "0" which is a pointer to a null terminated string. "0" is a string with '0' and a NULL terminator. No warnings here. But incorrect comparison nonetheless.

    You are possibly wanting to dereference the char pointer at ll_cur_rec and see if it equals '0'.

    if ((*pa_st.s_no)[ll_cur_rec] == '0')

    Also, check this : Single quotes vs. double quotes in C or C++