vc++相关程序问题

vc++相关指针操作问题以及其源代码……谢谢了……vc++……

img

需要保存到另一个数组吗?还是只有一个数组?两种代码都写了,根据你自己的需要选择吧,大多数情况用第一个代码就可以了。

img

原指针字符串逆序代码:

#include <iostream>
using namespace std;

void convers(char* s)
{
    char* t,*p, ch;
    t = s;
    p = s;
    while (*t != '\0')
        t++;
    t--;//t
    while (p < t)
    {
        ch = *p;
        *p = *t;
        *t = ch;
        p++;
        t--;
    }
}



int main()
{
    char buf[100];
    cin >> buf; //输入字符串
    convers(buf); //调用函数逆序
    cout << "逆序后:" << endl;
    cout << buf << endl;
    return 0;
}

从s指针逆序到t指针的代码:

#include <iostream>
using namespace std;

void convers(char* s,char* t)
{
    char *p, ch;
    p = s;
    while (*p != '\0')
        p++;
    p--;//t
    while (p >= s)
    {
        *t = *p;
        p--;
        t++;
    }
    *t = '\0';
}



int main()
{
    char buf[100], dst[100];
    cin >> buf; //输入字符串
    convers(buf,dst); //调用函数逆序
    cout << "逆序后:" << endl;
    cout << dst << endl;
    return 0;
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632