char数组取子字符串

memcpy 是存储块内容复制,存储块大小用 size_t 衡量。
void * memcpy ( void * destination, const void * source, size_t num );

strcpy
是字符内容复制
char * strcpy ( char * destination, const char * source );

都不会自动添加末尾终止符.

 

CString URL,strSentence;
  char ipinfo[MAX_PATH]={0};
 char devid[10] ,ipp[100]={0},user[50]={0},xuhao[10]={0};;
 sprintf(devid, "dev%d", pcc->nPort+1);

 sprintf(ipinfo, "219.141.202.229:8080,admin,1");
 char * pt=ipinfo;
 char * p=strchr(pt, ',');
  strncpy(ipp,pt,strlen(pt)-strlen(p));//
 ipp[strlen(pt)-strlen(p)]='\0';//ipp=219.141.202.229:8080

 pt=p;
 pt++;
 p=strchr(pt, ',');
 //printf("pt=%s\n",pt);
 strncpy(user,pt,strlen(pt)-strlen(p));
 user[strlen(pt)-strlen(p)]='\0';//user=admin
  

pt=p;
 pt++;
 //printf("pt=%s\n",pt);
 strncpy(xuhao,pt,strlen(pt));
 xuhao[strlen(pt)]='\0';
 URL.Format(_T("http://%s/gCubeManager/Loroller.jsp?username=%s"),ipp,user,);

 

//取出char数组中逗号之间的每个字符串

char buf[256]={0};
 sprintf(buf, "2013-04-09 11:12:11,hao,123456,aab,255,tt,200");
 char devds[7][50]={0};
 char * pt=buf;
 char * p;
 for (int i=0;i<6;i++)
 {
  p=strchr(pt, ',');
  strncpy(devds[i],pt,strlen(pt)-strlen(p));//
  devds[i][strlen(pt)-strlen(p)]='\0';//
  pt=p;
  pt++;
 }
 strncpy(devds[6],pt,strlen(pt));//

 

 

你可能感兴趣的:(char数组取子字符串)