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






#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