Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2003
    Location
    philippines
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can i format different strings

    how can i format different strings in Turbo C

    like

    char *a;
    char *b;


    a = "run";

    b = a + " go";


    i want to have a value of b is "run go", how can i do these ,
    i tryied this but errors occur. what are the other code.


    can you please help me

    thanks
    Let's help each other

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    India
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One way of concatenating strings in "C" is using the strcat function. For example,

    Code:
    char *a = "run";
    char *b = "go";
    char *c;
    
    c = (char *) malloc(strlen(a) + strlen(b) + 1);
    strcpy(c, a);
    strcat(c, b);
    If you would like to use the + operator to concatenate strings, you may have to use C++ or Java.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •