Initilizing char **string in C for use in soap structure function argument
I am using code generated with gSOAP, and need to use declarations as they have been provided if possible.
gSOAP's generated code provides the following prototype:
soap_call___accounts(struct soap *soap, struct _acnt *acnt, struct _resp *resp);
as well as the following struct definition:
struct _acnt
{
int sizeacnt;
char **acntNum;
};
In my calling application I need to send an account number such as "00000123" using the structure member acntNum
开发者_如何学Cas part of the acnt
argument in the calling function, but before it can be used to do that, it needs to be initialized.
How is char **acntNum
initialized?
See also the gSOAP 2.8.1 User Guide for more information.
Your soap function accepts an array of accounts. So you can not only call the soap function for the account "00000123", but also the two accounts ["00000123","00000456"] is possible in a single call.
To make this work, you must not only allocate memory, but also set the size parameter to the number of accounts you pass. For example you can do this:
struct acnt Accounts;
char *AccountToCheck = "00000123";
Accounts.sizeacnt=1;
Accounts.acntNum = malloc(1 * sizeof(*Accounts.acntNum));
Accounts.acntNum[0] = AccountToCheck;
soap_call___accounts(soap, &Accounts, &Response);
char *acntNumP = malloc(strlen("00000123")+1);
strcpy(acntNumP, "00000123");
char ** acntNum = &acntNumP;
Check for NULL
s where needed, of course.
精彩评论