#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>

#define MAX 50

typedef struct word_pair{
  char longer_word[10];
  char shorter_word[10];
  char combined_word[20];
  int longer_word_length;
  int shorter_word_length;
}word_pair_t;

word_pair_t create_word_pair(char *a, char *b);

int main()
{
	char a[MAX], b[MAX];
	word_pair_t str;

	printf("文字列を2つ入力してください。\n");
	printf("1つ目:");
	scanf("%s",a);
	printf("2つ目:"); 
	scanf("%s",b);
	str = create_word_pair(a, b);

	printf("長い方の文字列[%s]\n",str.longer_word);
	printf("短い方の文字列[%s]\n",str.shorter_word);
	printf("連結した文字列[%s]\n",str.combined_word);
	printf("長い方の文字列の長さ[%d]\n",str.longer_word_length);
	printf("短い方の文字列の長さ[%d]\n",str.shorter_word_length);

	return 0;
}

word_pair_t create_word_pair(char *a, char *b)
{
	word_pair_t str;
	size_t lena, lenb;
	int cmp;

	lena = strlen(a);
	lenb = strlen(b);
	if (lena == lenb) {
		cmp = strcmp(a, b);
	} else {
		cmp = lena - lenb;
	}

	if (cmp > 0) {
		strcpy(str.longer_word, a);
		strcpy(str.shorter_word, b);
	} else if (cmp < 0) {
		strcpy(str.longer_word, b);
		strcpy(str.shorter_word, a);
	} else {
		fprintf(stderr, "同じ文字列です\n");
		strcpy(str.longer_word, a);
		strcpy(str.shorter_word, "");
	}
	sprintf(str.combined_word, "%s %s", str.longer_word, str.shorter_word);
	str.longer_word_length = strlen(str.longer_word);
	str.shorter_word_length = strlen(str.shorter_word);

	return str;
}
