如何从函数返回C字符串并显示它

问题描述

我无法让我的程序显示整个C字符串,它仅显示第一个字母!我正在尝试编写一个函数,要求用户输入2个c字符串。然后,我有一个单独的功能来确定哪个c-sting按字母顺序更大,另一个要显示。每次显示c字符串时,它仅显示第一个字母。我不知道我在做什么错。我需要它来显示整个C字符串。

这是向用户询问两个c字符串的函数:

const char *getData(char *c,char *d)
{
    cout << "Enter the first c-string: ";
    cin.ignore();
    cin.getline(c,50);
    cout << "Enter the second c-string: ";
    cin.getline(d,50);
    return c,d;
}

这里是比较c字符串的函数

const char findBigger(char *c,char *d)
{
    if (strcmp(c,d) == 0)
        return *c;
    else if (strcmp(c,d) < 0)
        return *c;
    else if (strcmp(c,d) > 0)
        return *d;
}

这是显示输入和更大的c字符串的函数

void displayBigger(const char *c,const char *d,const char *maxChar)
{
    cout << "The first c-string is " << c << endl;
    cout << "The second char is " << d << endl;
    cout << "The bigger value is " << maxChar << endl;
    cout << "__________________________________________" << endl;
}

我在main()

char first[50],second[50]'
maxArray[50];
getData(first,second);
*maxArray = findBigger(first,second);
displayBigger(*first,*second,*maxArray);

程序的输出为:

Enter the first c-string: apple pie
Enter the second c-string: peach pie
The first char is a
The second char is p
The bigger value is a
__________________________________________

如何获取它来打印整个C字符串?它应该显示“苹果派”和“桃子派”

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)