|
-
December 18th, 2001, 03:38 AM
#1
Arrays(C++ question)
this is my function
char* clsRouterStub::CreateReqMsg(char* strParamListss,char strDelimiterss[])
{
char *strReturn = new char[100];
char *token;
int n;
char strParamList[]="a,bb,ccc,dddd";
char strDelimiter[]=",";
token = strtok( strParamListss, strDelimiter );
while( token != NULL )
{
if (token != "")
{
if (n>0)
n += sprintf(strReturn + n, "\317%s", token);
else
n = sprintf(strReturn , "%s", token);
}
token = strtok( NULL, strDelimiter );
}
return strReturn;
}
when i try to call it in following way then it doesn't take the correct value
Invocation :
char *strShakeHandReq = objRouterStub.CreateReqMsg("a,b,ccc,ddd",",");
while if i pass char a[20] = "a,b,ccc,ddd";
char b[10] = ",";
char *strShakeHandReq = objRouterStub.CreateReqMsg(a,b);
then it works why?
-
December 18th, 2001, 04:02 AM
#2
-
December 18th, 2001, 04:02 AM
#3
Re: Arrays(C++ question)
Because in the first case you are trying to pass a const char string but you haven't declared the function as such.
Regards,
The Beret.
-
December 18th, 2001, 05:19 AM
#4
Re: Arrays(C++ question)
you've said it is a C++ question but you've coded it all in C with the exception of the line where you used new (instead of malloc)
const should be used (in both C and C++) whenever you are not going to modify the string.
Also use * rather than [] when possible. (More efficient and, in my opinion, clearer)
Also why have you passed in strDelimiterss as a parameter then used your local strDelimiters?
And your local strParamList? Is this only for testing?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|