S
Sam
I have a situation occuring in my code and I just can't see to figure
out why
I have an structure called employee that will put all of the employee
id's into a char array set to 10
struct Employee
{
char employeeid[100]; /* id of
employee*/
};
I build an array of 2 employee id's - that I am using for test purposes
employee id 1 = 8989890
employee id 2 = 9839399
both of this id's match the ids that are in the database
Just for clarification the employee array contains the correct values
I then store the pointer of this structure off into another structure
for later processing
this structure looks like this
static struct
{
long p1; <---------where I am going to store the pointer to the
employee array
} u_hstmt
The code looks like this after the employee array is built
u_hstmt.p1 = (long)&employee[0].employeeid; //save off the address of
the employee structure //
return();
FYI - I have tried (long)&employee[0] instead of
(long)&employee[0].employeeid and get the same results - I think that
(long)&employee[0] is the proper approach correct? because I want to
point to the address of the first occurence in the array Right?
I am storing off the array to a pointer because later on the u_hstmt
structure is the standard way we recall and use an array of selected
records.
This is the code that is executed
status = getemployeeinfo(&(((EMPID)u_hstmt.p1)[count]));
EMPID equates to 10
count = 2
all said and done the called function uses
&(((EMPID)u_hstmt.p1)[u_hstmt[count] and equates it to a char * eid
All that being said
in the called function I do a display on eid and i see the 8989890(my
first valid eid from the original structure) and that goes on and does
it thing this tells me that I am on the right track
Then the second time the function is called i do a display on the eid
through the debugger tool and see that the value does not match
The second time I get 839399 as my second employee number when it
should be 9839399 - notice it is missing the first 9 in the employee id
- After some research I noticed that it is because it is off by one
character so if i were to go eid -1 then I would get 9839399 which is
the correct value for my second eid
the address value of the structure remains the same throughout only the
counter changes to get the next array of information.
Can someone tell me how my pointer to is getting the wrong information
for the second array if it is correct in the original structure and my
address that I am pointing too remains the intact? BTW I did not free
the original employee structure that I am pointing too.
Thanks
out why
I have an structure called employee that will put all of the employee
id's into a char array set to 10
struct Employee
{
char employeeid[100]; /* id of
employee*/
};
I build an array of 2 employee id's - that I am using for test purposes
employee id 1 = 8989890
employee id 2 = 9839399
both of this id's match the ids that are in the database
Just for clarification the employee array contains the correct values
I then store the pointer of this structure off into another structure
for later processing
this structure looks like this
static struct
{
long p1; <---------where I am going to store the pointer to the
employee array
} u_hstmt
The code looks like this after the employee array is built
u_hstmt.p1 = (long)&employee[0].employeeid; //save off the address of
the employee structure //
return();
FYI - I have tried (long)&employee[0] instead of
(long)&employee[0].employeeid and get the same results - I think that
(long)&employee[0] is the proper approach correct? because I want to
point to the address of the first occurence in the array Right?
I am storing off the array to a pointer because later on the u_hstmt
structure is the standard way we recall and use an array of selected
records.
This is the code that is executed
status = getemployeeinfo(&(((EMPID)u_hstmt.p1)[count]));
EMPID equates to 10
count = 2
all said and done the called function uses
&(((EMPID)u_hstmt.p1)[u_hstmt[count] and equates it to a char * eid
All that being said
in the called function I do a display on eid and i see the 8989890(my
first valid eid from the original structure) and that goes on and does
it thing this tells me that I am on the right track
Then the second time the function is called i do a display on the eid
through the debugger tool and see that the value does not match
The second time I get 839399 as my second employee number when it
should be 9839399 - notice it is missing the first 9 in the employee id
- After some research I noticed that it is because it is off by one
character so if i were to go eid -1 then I would get 9839399 which is
the correct value for my second eid
the address value of the structure remains the same throughout only the
counter changes to get the next array of information.
Can someone tell me how my pointer to is getting the wrong information
for the second array if it is correct in the original structure and my
address that I am pointing too remains the intact? BTW I did not free
the original employee structure that I am pointing too.
Thanks