wincc 環境下c語言處理字符串分割的strtok函數

void CTxtDemDlg::GetAddressAndUnit(char* str,char *Add,char *Unit,char *Name)
{
 char*p;
 char p1=',';
 p=strtok(str,&p1);
    strncpy(Add,str,strlen(p));
    int i=0;
    while(p!=NULL)
    {
     p=strtok(NULL,",");
     i++;
     if(i==1 && p!=NULL)
     {
      strncpy(Name,p,strlen(p));
     }
     else if(i==3 && p!=NULL)
     {
      strncpy(Unit,p,strlen(p));
      break;
     }
     else if(p==0)
     {
      break;
     }
    }
    
}函數

使用strtok函數在字符串str中用‘,’分割的字符串字符串

相關文章
相關標籤/搜索