concatenation of strings

This is a discussion on concatenation of strings within the C Programming forums, part of the General Programming Boards category; how we can concatenate more then two strings . without using multiple strcat statement. example i have char *a="program"; char ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    90

    concatenation of strings

    how we can concatenate more then two strings .
    without using multiple strcat statement.
    example
    i have
    char *a="program";
    char *b="lang";
    char *c= "clang";
    so how can i add these strings without using two strcat.
    if i use more then one strcat .
    my execution times increases so how can i reduce it
    thank u
    sree

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    you cannot reduce execution time. You can however - write it with 1 line using sprintf

    sprintf(resbuf, "%s%s%s",a,b,c);

    Here there is a possibility of memory overrun, so I always use some snprintf equivalent
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It's a bit of a laugh if you believe that somehow, despite the fact that you don't know how to code a string concatenate function, that you're going to (with a bit of help), write up something much more efficient than the standard library function.



    If your execution time is increasing, perhaps your function could be in-lined, but that's up to your compiler to accept or reject.

    If you'll step through your code, dollars to donuts, your code is wasting time mis-using the strcat function. When you step through your code, you'll see it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  3. Concatenation of strings as char pointers
    By sameerc in forum C Programming
    Replies: 11
    Last Post: 05-10-2005, 04:23 PM
  4. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

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