[問題] VS2012: 字串中的字元無效。
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
visual studio 2010,2012
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
none
問題(Question):
原po使用base64演算法,程式碼如下
unsigned char *base64(string inpt,int * len)
{
int n,i,j,pad;
unsigned char *p = NULL;
unsigned char *dst = NULL;
unsigned char * src = NULL;
*len=0;
pad=0;
n=inpt.length();
src=new unsigned char [n];
for(i=0;i<n;i++)
src[i]=inpt[i];
while(n>0&&src[n-1]=='=') {
src[n-1]=0;
pad++;
n--;
}
for(i=0;i<n;i++) { /* map base64 ASCII character to 6 bit value */
p=(unsigned char *)strchr((const char *)base64,(int)src[i]);
if(!p)
break;
src[i]=p-(unsigned char *)base64;
}
dst=(unsigned char *)malloc(n*3/4+1);
memset(dst,0,n*3/4+1);
for(i=0,j=0;i<n;i+=4,j+=3) {
dst[j]=(src[i]<<2) + ((src[i+1]&0x30)>>4);
dst[j+1]=((src[i+1]&0x0F)<<4) + ((src[i+2]&0x3C)>>2);
dst[j+2]=((src[i+2]&0x03)<<6) + src[i+3];
*len+=3;
}
*len-=pad;
return dst;
}
該程式碼在vs2010執行正常,但在vs2012則會回傳 <字串中的字元無效。>
哪裡設定錯了嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.33.207.109
※ 編輯: sohumi 來自: 114.33.207.109 (09/25 21:02)
推
09/30 01:56, , 1F
09/30 01:56, 1F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章