[圖解C] ex 6-7

// exercise 6-7: copy and attach string2 to string1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char strA[30],
         strB[30],
         strAB[60];
       
    int i=0, j;
   
    // gets() can receive space
    gets(strA);
    gets(strB);
   
    // clear remain value of strAB
    while (i != 60){
       strAB[i] = '\0';
       i++;
    }
    printf("%s\n", strAB);
   
    // put strA into strAB
    i=0;
    while (strA[i] != '\0'){
       strAB[i] = strA[i];
       i++;
    }
   
    // attach strB to strA in strAB
    j=0;
    while (strB[j] != '\0'){
       strAB[i] = strB[j];
       i++;
       j++;
    }
   
    printf("%s\n", strAB);
   
    system("pause");
    return 0;
}