
March 12th, 2002, 05:30 AM
|
|
Junior Member
|
|
Join Date: Mar 2002
Location: Norway
Posts: 0
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
return addr of an struct-array
Why doesn't this give the expected result:
Code:
/* start cpp-code */
struct option
{
char *option2;
char *value;
};
option *getOption(char *chrOption, int intMaxOption)
{
option *myOption;
myOption = new option[intMaxOption];
//code to fill myOption with elements
return myOption;
}
int main(int argc, char* argv)
{
option *myOption;
char *test="opt1=222&opt2=333";
myOption = getOption(test, 5);
//all values in myOption gives the same as the
//last filled value in myOption.
//ex. myOption[0].option2 will give the same as
//myOption[2].value, even if they have different
//values in the getOption function...
return 0;
}
/* end cpp-code */
Yes, I know this could be done easier with classes in C++,
but would like to have a solusion to this problem.
-------
Lars Andre
URL
|