I need to prompt the user to enter two strings and then create a third string with the first half of string1 and the second half of string2. I was able to put the first half of string1 into string3 but I cannot figure out how to put the second half of string2 into string 3. Here's my code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
int main ()
{
char string1[255], string2[255], string3[255];
int string1Len = 0, string2Len = 0;
printf ("Enter String 1: ");
fgets (string1, 255, stdin);
string1[strlen(string1) - 1] = '\0';
string1Len = strlen(string1);
printf ("Enter String 2: ");
fgets (string2, 255, stdin);
string2[strlen(string2) - 1] = '\0';
string2Len = strlen(string2);
printf ("String 1 is %d bytes long and String 2 is %d bytes long.\n", string1Len, string2Len);
strncpy (string3, string1, string1Len / 2);
string3[string1Len / 2] = '\0';
strcat (string3, " ");
strncat (string3, string2, string2Len / 2);
printf ("String 3 is: %s\n", string3);
system("pause");
return 0;
}