I'm working on a code that takes two strings and outputs one string with the following output:
s1 = abc
s2 = def
output s3 = adbecf
if string 1 has more than 3 characters, those characters are placed in the back. Same thing with string 2:
s1 = abcwxy
s2 = deflmn
output s3 = adbecfwxylmn
I'm pretty sure I have the answer but I keep getting an error in the compiler. What's going on? Can someone help me run it and tell me what error you get too please?
Code:
include<math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
/*
* Complete the function below.
*/
char* mergeStrings(char* a, char* b) {
//char* arr;
int alen = strlen(a);
int blen = strlen(b);
int len = alen + blen;
char arr[len];
int i = 0, j = 0, k = 0;
while(i < alen && j < blen){
arr[k++] = a[i++];
arr[k++] = b[j++];
}
while(i < alen){
arr[k++] = a[i++];
}
while(j < blen){
arr[k++] = b[j++];
}
return arr;
}
int main() {
FILE *f = fopen(getenv("OUTPUT_PATH"), "w");
char* res;
char* _a;
_a = (char *)malloc(512000 * sizeof(char));
scanf("\n%[^\n]",_a);
char* _b;
_b = (char *)malloc(512000 * sizeof(char));
scanf("\n%[^\n]",_b);
res = mergeStrings(_a, _b);
fprintf(f, "%s\n", res);
fclose(f);
return 0;
}