#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char ary_name[20];
char ary_vname[20];
memset(ary_name,0x0,10);
sprintf(ary_name,"%s","我是中國人");
strcpy(ary_name,"字串數組賦值");
printf("ary_name=%s\n",ary_name);
memcpy(ary_vname,ary_name,sizeof(ary_name));
printf("ary_vname=%s\n",ary_vname);
char buf[20] = "hello world\n";
memcpy(buf + 1, buf, 13);
printf("%s\n", buf);
strcpy(buf,"hello world\n");
memmove(buf + 1, buf, 13); /*memcpy與memmove區別memcpy在於記憶體區間如果重疊則無法保證正確拷貝*/
printf("%s\n", buf);
if(strcmp(ary_name,ary_vname)==0)
{
printf("ary_name==ary_vname相同\n");
}
char *s="www.csdn.net";
char *l="csdn";
char *k="中";
char *pstr;
pstr=strstr(s,l);
printf("pstr=%s\n",pstr);
char *v=ary_name;
printf("v=%s\n",v);
char *pstr2;
pstr2=strstr(v,k);
if(pstr2!=NULL)
{
printf("pstr2=%s\n",pstr2);
}else{
printf("pstr2沒發現\n");
}
/*字串分拆*/
char str[]="abc:dded:天空:海洋:大地:abcd";
char *token;
token=strtok(str,":");
printf("%s\n", token);
while((token=strtok(NULL,":"))!=NULL)
{
printf("%s\n",token);
}
return 0;
}