#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
static char str1[256] = "apple orange fruit cocktail.\0";
static char str2[256] = "mama/\0";
printf("string = %s\nword = %s\n",str1,str2);
char* buf = str1; int count = 0;
while ((buf = strchr(buf,' ')) != NULL)
{
int len = strlen(str2)+1;
while (--len >= 0 && !(count % 2))
{
for (int q = strlen(str1)-1; q >= buf-str1; q--)
str1[q+1] = str1[q];
}
if ((count % 2) == 0)
memcpy((void*)++buf, (void*)str2, strlen(str2));
buf+=strlen(str2)+1; count++;
}
if ((buf = strchr(str1,'.')) != NULL && !(count % 2))
{
*buf = ' ';
memcpy((void*)++buf, (void*)str2, strlen(str2));
if ((buf = strchr(buf,'/')) != NULL) *(buf+1) = '.';
}
printf("output = %s\n",str1);
return 0;
}