CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2001
    Posts
    169

    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?



  2. #2
    Join Date
    Sep 2001
    Posts
    169

    Re: Arrays(C++ question)

    now it is been solved.


  3. #3
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    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.



  4. #4
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    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
  •  





Click Here to Expand Forum to Full Width

Featured