C语言字符串复制
strcpy(arg1,arg2);//将arg2内容赋值到arg1
strncpy(arg1,arg2,size);//赋值多少由size决定,如果要截取某一部分,可以将arg2指针进行arg2+x操作。
例如strncpy(arg1,arg2+1,2);//arg1从第二个位置开始,赋值两个字节到arg1,如果arg1=“abcd”,则arg2=“bc”
memcpy(arg1,arg2,size);//arg2的size个字符复制到arg1
sprintf();//格式化某个参数到字符串中,详细见百度百科
snprintf(arg1,size,"%s-%d....",str1,str2);//格式化复制到arg1,详细见百度百科
例子
snprintf(now_date,16,"%04d-%02d-%02d",(1900+timeinfo->tm_year),(1+timeinfo->tm_mon),
timeinfo->tm_mday);
snprintf (mac, len_limit, "%02x%02x%02x%02x%02x%02x",
(unsigned char) ifreq.ifr_hwaddr.sa_data[0],
(unsigned char) ifreq.ifr_hwaddr.sa_data[1],
(unsigned char) ifreq.ifr_hwaddr.sa_data[2],
(unsigned char) ifreq.ifr_hwaddr.sa_data[3],
(unsigned char) ifreq.ifr_hwaddr.sa_data[4],
(unsigned char) ifreq.ifr_hwaddr.sa_data[5]);