char* buf = "安吉轻松2日游";
int len; char * tmp = NULL; len = sizeof(char);//len=strlen(buf);strlen是指一个字符串的实际长度,从开始算到'\0'结束,而sizeof指一个数组定义的类型容量大小tmp = (char*)malloc(len);
memset(tmp,0x00,len);//初始化指针内存 strcpy(tmp,buf); printf("tmp=%s\n",tmp); free(tmp);------------------------------------------------------------------
NetParameter lNetParam; memset(&lNetParam,0,sizeof(NetParameter));//初始化结构内存 strcpy((char *)lNetParam.configversion,"004vwer"); strcpy((char *)lNetParam.ssid,"AP1234"); strcpy((char *)lNetParam.ipaddr,"172.16.8.125"); strcpy((char *)lNetParam.mask,"004vwer"); strcpy((char *)lNetParam.gateway,"004vwer"); strcpy((char *)lNetParam.dns1,"004vwer"); strcpy((char *)lNetParam.dns2,"004vwer"); printf("configversion=%s\nssid=%s\nipaddr=%s\n",lNetParam.configversion,lNetParam.ssid,lNetParam.ipaddr); ----------------------------------------------------------------- char *serveraddr="172.16.8.125"; char serverip[20]={0}; memset(serverip,0,20);//初始化数组内存 strcpy(serverip,serveraddr); printf("serverip=%s\n",serverip);