注册 登录
编程论坛 C++教室

写了一个字符转换的小程序,但是不知道哪里出错了,帮忙看一下。

阿冲 发布于 2009-10-05 13:23, 713 次点击
程序代码:
#include <iostream>
#include <string.h>
using namespace std;
void sValue(char szA);
int main()
{
    char szValue[10]={0};
    cin >> szValue;
    sValue(szValue);
    return 0;
}
void sValue(char szA)
{
    char arrValue[] = "abcdefg";
    char *pA = arrValue;
    int iInfo = strlen(arrValue)-1;
   
    for (int i = iInfo; i>=0; i--)
    {
        cout << *(pA + i);
    }
    cout << szA << endl;
}

这段代码的功能是将输入的字符串按反方向输出,但是现在出错了,找了一上午也没找出原因,请大家帮忙指正。
1 回复
#2
haitao99992009-10-05 18:56
修改了你的程序,以下为代码,运行良好。
分析:你的程序1是转换函数有问题,sValue函数参数应该是字符指针,这样才能接爱字符串作为实参.2是函数功能部分有问题我改了下,可以具休看下。
#include <iostream>
#include <string.h>
using namespace std;
void sValue(char *szA);
int main()
{
    char szValue[10]={0};
    char *pszValue = szValue;
    cout<<"请准确输入10个字符后回车"<<endl;
    cin >> pszValue;
    sValue(pszValue);
    return 0;
}
void sValue(char *szA)
{
    char *pA = szA;
    int iInfo = strlen(szA)-1;
     
    for (int i = iInfo; i>=0; i--)
    {
        cout << *(pA + i);
    }
     
}
1