c++里,使用 char * pOutputstr,对其赋值后出现乱码,代码如下:
#include <iostream>
using namespace std;
void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr)
{
int count=1;
int order=0;
for(int i=0;i<lInputLen-1;i++)
{
char a=pInputStr[i];
char b=pInputStr[i+1];
if(a==b)
{
count++;
}
else
{
pOutputStr[order++]=count;//此处赋值出现乱码
//cout<<count;
pOutputStr[order++]=a;
//cout<<a;
count=1;
}
}
pOutputStr[order++]=count;
pOutputStr[order++]=pInputStr[strlen(pInputStr)-1];
}
int main()
{
char strings[100];
cout<<"Input your string:"<<endl;
cin>>strings;
stringZip(strings,strlen(strings),strings);
cout<<strings<<endl;
char keep=' ';
cin>>keep;
}
望各位好友帮忙看看,错在哪了 |