title: c++ cstring merge and sort programming without using string library
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int strlength(char *str)
  {
      int length = 0;
      int index = 0;
      while (*(str + index)) {
          length++;
          index++;
      }
      return length;
  }
  
  char *mergeSortedStrings(char str1[], char str2[])
  {   //get the length of the newstring
      int str1len = strlength(str1);
      int str2len = strlength(str2);
      int newStringlen = str1len + str2len;
      char *newString= new char[newStringlen];
      int i, j = 0;
      char temp;
      // copy str2 to the end of str1
      for (i = strlength(str1); i&lt;256; i++)
      {
          str1[i] = str2[j];
          j++;
      }
  
      for (i=0; i&lt;newStringlen;i++)
          for (j = newStringlen - 1; j &gt; i; j--) {
              if (str1[j - 1] &gt; str1[j])
              {
                  temp = str1[j];
                  str1[j] = str1[j - 1];
                  str1[j - 1] = temp;
  
              }
          }
      str1[newStringlen] = '\0';
      return str1;
  }
  
  
  void main()
  {
      char str1[20];
      char str2[20];
  
      cout &lt;&lt; "Input string 1: ";
      cin &gt;&gt; str1;
      cout &lt;&lt; "Input string 2: ";
      cin &gt;&gt; str2;
  
      cout &lt;&lt; "The merged string is: " &lt;&lt; mergeSortedStrings(str1, str2) &lt;&lt; endl;
  }
  </code></pre>
  
  <p>This is C++ string merge and sort programming without using string library functions. When I copied the contents of the final str1 to newString using for loop, it didn't give the correct result so that I just used str1 as the result. It gives out the correct result somehow but I think this may not be efficient. 
  Can you please help me with this?</p>