我有字符串
char *pbuf='asdhadfsohasodfgaosgdoiuwqeiureuasdasdasd';如何从pbuf左边依次取5位字符

解决方案 »

  1.   

    CString rrr;
    rrr=buf;
    CString kkk;
    kkk=rrr.Left(5);
      

  2.   

    char strItem[6];strncpy(strItem,pbug,5);
    strItem[5]='\0';
      

  3.   

    char newchar;
    for(int index=0;index<5;index++)
    {
        newchar=pbuf[index];
    }
      

  4.   

    pbuf="asdljapldfjapsdfgaposgjasjgasgjasjgjafjag";
    我的意思是第一次取‘asdlj’,第二次取‘apldf’,第三次取‘japsd’怎样写个循环
      

  5.   

    int nCount;
    int nIndex=0;
    char strItem[6];
    nCount=strlen(pbuf);
    while(nIndex<nCount)
    {
        if(nIndex+5<nCount)
            strncpy(strItem,pbuf,nIndex,5);    else
            strncpy(strItem,pbuf,nIndex,nCount-1);
        strItem[5]='\0';
        nIndex+=5;
    }
      

  6.   

    出错
    strncpy' : function does not take 4 parameters
      

  7.   

    int nCount;
    int nIndex=0;
    CString ret;
    CString kkk;
    kkk=pbuf;
    nCount=strlen(pbuf);
    while(nIndex<nCount)
    {
        if(nIndex+5<nCount)
            ret=kkk.Mid(nIndex,nIndex+5);
        else
            ret=kkk.Mid(nIndex,nCount)
        nIndex+=5;
    }