I have simple function that should connect string but in different way. If i have one string "abc" and another "123" final string should be "a1b2c3".
Here is code
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
char *connStrings(char *s1, char *s2) {
int s1L, s2L,i = 0,k=1,j=0;
s1L = sizeof(s1);
s2L = sizeof(s2);
char* result = (char*) malloc((s1L + s2L));
while (s1[i] != '\0') {
result[j] = s1[i++];
j = j + 2;
}
i = 0;
while (s2[i] != '\0') {
result[k] = s2[i++];
k = k + 2;
}
result[s1L + s2L] = '\0';
printf("\n %s \n", result);
}
int main() {
connStrings("abcdefghi","123456789");
}
So what's the problem?
the final output of this program is still the same "a1b2c3d4e5f6g7h8"
It ignores i and 9 somehow. Even if I add more chars into both strings it still prints the same
"a1b2c3d4e5f6g7h8". I will be thankful for any help or advice.