Share on Google+Share on Google+

C String Join

Advertisement
In this section, you will learn how to join the strings. You can see in the given example, we have define two strings and initializes two integer variables length1 and length2 to 0.

C String Join

     

In this section, you will learn how to join the strings. You can see in the given example, we have define two strings and initializes two integer variables length1 and length2 to 0. Then consider the length1 as the length of the string s1 and length2 as the length of string s2
Now set the length2 to 0 and by using while loop equate the two strings. Finally, the string st1 joins to st2.

Here is the code:

STRINGJO.C

#include <stdio.h>
#include <conio.h>
int main() {
  char s1[40"WEL";
  char s2[] "COME";
  int length1 = 0;
  int length2 = 0;
  while (s1[length1])
  length1++;
  while (s2[length2])
  length2++;
  length2 = 0;
  while (s2[length2]) {
  s1[length1++= s2[length2++];
  }
  printf("\n%s\n", s1);
  getch();
  return 0;
}

Output will be displayed as:

STRINGJO.EXE

Download Source Code:

Advertisements

Posted on: February 6, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: C String Join  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0