定义字符数组,调用字符串函数处理

编写程序实现以下功能:定义两个元素个数为20的字符数组str1、str2,然后输入两个字符串保存到str1、str2中,现调用字符串处理函数分别进行以下处理:

(1)分别计算两个字符串的长度并输出;

(2)输出两个字符串中得较大值。

(3)定义一一个字符数组str,将str1、str2两个字符串连接后保存到str中输出。

你是要写三个函数吗?

/*
编写程序实现以下功能:定义两个元素个数为20的字符数组str1、str2,然后输入两个字符串保存到str1、str2中,现调用字符串处理函数分别进行以下处理:
(1)分别计算两个字符串的长度并输出;
(2)输出两个字符串中得较大值。
(3)定义一一个字符数组str,将str1、str2两个字符串连接后保存到str中输出。
*/
#include <iostream>
using namespace std;
int getlen(char *s)
{
    int i=0;
    while(s[i++] != 0);
    return i-1;
}
int getmax(char *s1,char *s2)
{
    int i=0;
    while(s1[i] != 0 &&s2[i] != 0)
    {
        if(s1[i] > s2[i])
              return 1;
        else if(s1[i] < s2[i])
              return -1;
        i++;
    }
    if(s1[i] == 0 && s2[i] ==0)
        return 0;
    if(s1[i] != 0)
        return 1;
    return -1;
}

void combStr(char *s1,char *s2,char *s3)
{
    int i=0,j=0;
    while(s1[i] != 0)
    {
        s3[i] = s1[i];
        i++;
    }
    while(s2[j] != 0)
    {
        s3[i] = s2[j];
        i++;
        j++;
    }
    s3[i] = 0;
}
int main()
{
      char s1[20],s2[20],s3[40];
      gets(s1);
      gets(s2);
      cout<<getlen(s1)<<endl;
      cout<<getlen(s2)<<endl;
      if(getmax(s1,s2) > 0)
            cout<<s1<<endl;
      else
            cout<<s2<<endl;
      combStr(s1,s2,s3);
      cout<<s3;
      return 0;
}