본문 바로가기

C언어/프로그래머스

[c언어] 문자열 겹쳐쓰기

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


char* solution(const char* my_string, const char* overwrite_string, int s) {
 
    int m = strlen(my_string);
    int o = strlen(overwrite_string);
    int j = 0;
    
    char* answer = (char*)malloc(sizeof(char)*m);
    
    answer = my_string;
    
    for(int i=s; i < s+o; i++) {
        answer[i] = overwrite_string[j];
        j++;
    }
    
    answer[strlen(my_string)] = '\0';
    return answer;
}