본문 바로가기

C언어/프로그래머스

[c언어] 문자열 섞기

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


char* solution(const char* str1, const char* str2) {
 
    int s1 = strlen(str1);
    char* answer = (char*)malloc((2*s1+1)*sizeof(char));
    
    int j = 0;
    
    for(int i=0; i < s1; i++)
    {
        answer[j++] = str1[i];
        answer[j++] = str2[i];
    }
    
    answer[j] = '\0';
    
    return answer;
}