-
Notifications
You must be signed in to change notification settings - Fork 0
/
1768.c
33 lines (31 loc) · 830 Bytes
/
1768.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char * mergeAlternately (const char * word1, const char * word2)
{
char * asd = (char *)malloc(strlen (word1) + strlen (word2) + 2);
const char * ch1, * ch2;
unsigned long int j = strlen (word1), p = strlen (word2);
ch1 = word1;
ch2 = word2;
for (unsigned long int i = 0; i <= j && i <= p; i ++)
{
asd[2 * i] = *(ch1 + i);
asd[2 * i + 1] = *(ch2 + i);
}
if (j > p)
{
for (unsigned long int i = 0; i <= j - p; i ++)
{
asd[2 * p + i] = *(ch1 + p + i);
}
}else if (j < p)
{
for (unsigned long int i = 0; i <= p - j; i ++)
{
asd[2 * j + i] = *(ch2 + j + i);
}
}else;
asd[strlen (word1) + strlen (word2)] = '\0';
return asd;
}