Joining strings without using strcat : String Join « String « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » String » String Join 
3.6.1.Joining strings without using strcat
#include <stdio.h>

int main(void)
{
  char str1[40"AAA";
  char str2[] "BBBB";
  int str1Length = 0;             
  int str2Length = 0;             

  while (str1[str1Length])          
    str1Length++;                   

  while (str2[str2Length])          
    str2Length++;


  if(sizeof str1 < str1Length + str2Length + 1)
    printf("\n str1 is too short.");
  else
  {  
    str2Length = 0;                 
    while(str2[str2Length]){   
      str1[str1Length++= str2[str2Length++];
    }

    str1[str1Length'\0';        
    printf("\n%s\n", str1 );     

  }
  return 0;
}
AAABBBB
3.6.String Join
3.6.1.Joining strings without using strcat
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.