char xx[10];
CString strXX;
strXX="中国人当自强!xxx之强不惜";请教一下,我现在需要把strXX的内容分配到char xx[10]数组里N次,应该怎么写呢??strcpy();行不通,考出来的一半是乱码啊???先谢谢了,很急,望各位指点迷津。先谢谢了。
CString strXX;
strXX="中国人当自强!xxx之强不惜";请教一下,我现在需要把strXX的内容分配到char xx[10]数组里N次,应该怎么写呢??strcpy();行不通,考出来的一半是乱码啊???先谢谢了,很急,望各位指点迷津。先谢谢了。
然后进行copy
是分批次将strXX的内容一段段地拷到xx缓冲里吗?
CString strXX = "中国人当自强!xxx之强不惜";
char* p = xx;
for (int i=0; i<N; i++)
{
p += sprintf(p, "%s", (LPCTSTR)strXX);
}
char* pxx 代替 char xx[10]另外:我现在需要把strXX的内容分配到char xx[10]数组里N次
是指 xx[10]作为缓冲要把strXX的内容拷贝出来吗?没弄明白
没错就是这个意思,每次显示xx的内容,缓冲只有这么大,这个是没法改变的,第三方的软件只能接受这个长度的char个数。但是每次都要保证给他的都是完整的内容。不能出现乱码。晕死啊!!
char xx[10] = {0};
CString strXX = "中国人当自强!xxx之强不惜";
int nTimes = strXX.GetLength() / 9;
LPCTSTR pStr = (LPCTSTR)strXX;
for ( int n = 0; n < nTimes; n++ )
{
strncpy( xx, pStr, 9 ); // 如果这里编译有类型转换错误,说明你用的是UNICODE环境
// 处理xx数据
pStr += 9;
}
int i=0;
int j=0;
LPCTSTR p = strXX;
char* cTemp = new char;
do
{
if (i%10==0)
{
xx[j] = '\0';
j=0;
}
*cTemp = (char) *((char*)(p+i));
if (IsDBCSLeadByte((BYTE)cTemp))
{
xx[j] = *cTemp;
xx[++j] = (char) *((char*)(p+(++i)));
}
j++;
i++;
} while(i<=strXX.GetLength());
delete cTemp;
再把每10个以数组一样赋值给你的10长度的char数组 直到 临时对象结尾
{
....
char xx[10];
CString strXX;
strXX="中国人当自强!xxx之强不惜";
for(int i = 0; i < N; i++)
{
......
int nLen = 0;
nLen = strXX.GetLength() > 9 ? 9 : strXX.GetLength(); strncpy(xx, strXX.GetBuffer(strXX.GetLength()), nLen); //....
.....
//....
ZeroMemory(xx, 10);
strXX.Empty();
}
}
char xx[10];
memset(xx,0,sizeof(xx));
CString strXX;
strXX="中国人当X自强!xxx之强不惜";
char *p = NULL,*p1 = NULL,*p2 = NULL;
BYTE bt;
int nLength = 0;
int nLen = sizeof(xx);
nLength = strXX.GetLength();
p = strXX.GetBuffer(strXX.GetLength());
while(p!=NULL && strlen(p)>0)
{
memset(xx,0,sizeof(xx));
if(strlen(p)<nLen)
{
nLen = strlen(p)+1;
}
p1 = p+nLen-1;
bt = BYTE(*p1);
if(bt>0x80)
{
p2 = p1 - 1;
bt = BYTE(*p2);
if(bt>0x80)
{
memcpy(xx,p,p1-p-1);
p = p + (p1-p-1);
}
else
{
memcpy(xx,p,p1-p);
p = p + (p1-p);
}
}
else
{
memcpy(xx,p,p1-p);
p = p + (p1-p);
}
TRACE("%s",xx);
}
CString cTmp1=strXX;
char ch[3];
int i=0;
while (cTmp1 != "")
{
if (cTmp1.GetAt(0) & 0x80)//汉字
{
if(i<9)
{
ch[i] = cTmp1.GetAt(0);
ch[i+1] = cTmp1.GetAt(1);
cTmp1.Delete(0,2);
i++;
}
else
break;
}
else//非汉字
{
if (i<10)
{
ch[i] = cTmp1.GetAt(0);
cTmp1.Delete(0,1);
i++;
}
else
break;
}
}
[/code]
何解?
可以定义一个结构体数组
里面包含char
这样可以直接赋给它了
strcpy(p,strXX.GetBuff);
strXX.ReleaseBuffer();这样肯定没问题
char xx[100];
CString strXX = L"中国人当自强!xxx之强不惜";
strcpy(xx, W2A(strXX));
AfxMessageBox(CString(xx));