Sending character string value as argument ??

This is a discussion on Sending character string value as argument ?? within the C Programming forums, part of the General Programming Boards category; Hi, I want to send the value of a character string . I just want to pass the character string ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    3

    Sending character string value as argument ??

    Hi,

    I want to send the value of a character string . I just want to pass the character string as literal.

    For Example:-

    Code:
    Char temp[50];
    temp contains:- "<Request>{requestRefund}</Request>"

    I want to place this temp literally including double quotes(") in fucntion refund as an argument.

    Code:
    void refund ("initials", temp, "status");
    //Is this the correct way to pass the temp..??...any ideas
    //It should show like ("initials","<Request>{requestRefund}</Request>","status");


    Another,

    Code:
    web_custom_request("Anyname", temp, LAST);
    //is this the correct way to pass temp, so that temp will get replaced with "<Request>{requestRefund}</Request>" and it should look like:- web_custom_request("Anyname", "<Request>{requestRefund}</Request>",LAST);


    Please help...Thanks in advance

    Regards
    Pawan

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You'll only have a pointer of the string literal, so just pass that.
    Code:
    void foo(const char * xxx)
    {
         /* do whatever with xxx */
    }
    
    /* ... */
    foo("this is string literal");
    Just don't modifiy xxx, otherwise there are various things that can (or won't) happen.

    Note that passing a pointer to an array with the string in it, and a pointer to the string literal are very different. The content, and the pointers may be the same, but you (usually) can't modify string literals as they reside in read-only memory.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    87
    Quote Originally Posted by Pawan Sangal View Post
    Hi,

    Code:
    Char temp[50];
    I want to place this temp literally including double quotes(") in fucntion refund as an argument.

    Code:
    void refund ("initials", temp, "status");
    //Is this the correct way to pass the temp..??...any ideas
    //It should show like ("initials","<Request>{requestRefund}</Request>","status");

    [/code]
    Define your function to take an argument of type char[] or char * and you can pass temp like that. As for the other arguments, either do the same or if they used to indicate some kind of code maybe make them (integer) constants?

    If you do want to pass a string, and you do want there to be double quotes, you can use the escape character '\' to get them in there. For example, if I wanted a string to read "initials", including the quotes, I would do "\"initials\"". Your function should take a const char *for that parameter if indeed you needed to pass a sting literal like that.

    Jason

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    3
    Quote Originally Posted by jason_m View Post
    Define your function to take an argument of type char[] or char * and you can pass temp like that. As for the other arguments, either do the same or if they used to indicate some kind of code maybe make them (integer) constants?

    If you do want to pass a string, and you do want there to be double quotes, you can use the escape character '\' to get them in there. For example, if I wanted a string to read "initials", including the quotes, I would do "\"initials\"". Your function should take a const char *for that parameter if indeed you needed to pass a sting literal like that.

    Jason


    Thanks Jason......

    let me try this as you suggested. I hope it will help me in finding the solution to my problem.

    Regards
    Pawan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. Sending a string to C++ from VB 6.
    By VirtualAce in forum C++ Programming
    Replies: 4
    Last Post: 08-21-2001, 03:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21