strcat

This is a discussion on strcat within the C Programming forums, part of the General Programming Boards category; Hi, I am a newbie in C. I want to concatenate two strings as follows. char InvNo[15]="12345"; char *InvNoStr; InvNoStr=strcat("INVOICE ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    8

    strcat

    Hi,

    I am a newbie in C.

    I want to concatenate two strings as follows.

    char InvNo[15]="12345";
    char *InvNoStr;

    InvNoStr=strcat("INVOICE NO: ",InvNo);


    which returns only 'INVOICE NO:'

    can anybody advise?

    thanks you,

    Thomas

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    "INVOICE NO: " is a string literal. You can't append to that. You could instead copy that first to an array, and then strcat the InvNo onto the end of that array.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    27
    How about this:
    Code:
    ssprintf(InvNoStr,"INVOICE NO:%s",InvNo);

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    74
    its more like quzah said:

    Code:
    char InvNo[18] = "INVOICE NO: ";
    
    strcat(InvNo , "12345");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An interesting question about strcat
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2009, 01:59 PM
  2. String Concatenation Using Pointers No strcat()
    By oviang in forum C Programming
    Replies: 4
    Last Post: 12-07-2007, 10:31 AM
  3. strcat and a char
    By jjacobweston in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2005, 05:10 PM
  4. strcat makes program crash
    By imoy in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2002, 03:41 PM
  5. Removing 'strcat' ed string.
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-14-2001, 12:09 AM

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