您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > C/C++资料 > C语言字符串函数大全
¹¦ÄÜ:¿½±´Ò»¸ö×Ö·û´®µ½ÁíÒ»¸öÓ÷¨:char*stpcpy(char*destin,char*source);³ÌÐòÀý:#includestdio.h#includestring.hintmain(void){charstring[10];char*str1=abcdefghi;stpcpy(string,str1);printf(%s\n,string);return0;}º¯ÊýÃû:strcat¹¦ÄÜ:×Ö·û´®Æ´½Óº¯ÊýÓ÷¨:char*strcat(char*destin,char*source);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){chardestination[25];char*blank=,*c=C++,*Borland=Borland;strcpy(destination,Borland);strcat(destination,blank);strcat(destination,c);printf(%s\n,destination);return0;}º¯ÊýÃû:strchr¹¦ÄÜ:ÔÚÒ»¸ö´®ÖвéÕÒ¸ø¶¨×Ö·ûµÄµÚÒ»¸öÆ¥ÅäÖ®´¦\Ó÷¨:char*strchr(char*str,charc);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){charstring[15];char*ptr,c='r';strcpy(string,Thisisastring);ptr=strchr(string,c);if(ptr)printf(Thecharacter%cisatposition:%d\n,c,ptr-string);elseprintf(Thecharacterwasnotfound\n);return0;}º¯ÊýÃû:strcmp¹¦ÄÜ:´®±È½ÏÓ÷¨:intstrcmp(char*str1,char*str2);¿´AsicÂ룬str1str2£¬·µ»ØÖµ0£»Á½´®ÏàµÈ£¬·µ»Ø0³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){char*buf1=aaa,*buf2=bbb,*buf3=ccc;intptr;ptr=strcmp(buf2,buf1);if(ptr0)printf(buffer2isgreaterthanbuffer1\n);elseprintf(buffer2islessthanbuffer1\n);ptr=strcmp(buf2,buf3);if(ptr0)printf(buffer2isgreaterthanbuffer3\n);elseprintf(buffer2islessthanbuffer3\n);return0;}º¯ÊýÃû:strncmpi¹¦ÄÜ:½«Ò»¸ö´®ÖеÄÒ»²¿·ÖÓëÁíÒ»¸ö´®±È½Ï,²»¹Ü´óСдÓ÷¨:intstrncmpi(char*str1,char*str2,unsignedmaxlen);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){char*buf1=BBB,*buf2=bbb;intptr;ptr=strcmpi(buf2,buf1);if(ptr0)printf(buffer2isgreaterthanbuffer1\n);if(ptr0)printf(buffer2islessthanbuffer1\n);if(ptr==0)printf(buffer2equalsbuffer1\n);return0;}º¯ÊýÃû:strcpy¹¦ÄÜ:´®¿½±´Ó÷¨:char*strcpy(char*str1,char*str2);³ÌÐòÀý:#includestdio.h#includestring.hintmain(void){charstring[10];char*str1=abcdefghi;strcpy(string,str1);printf(%s\n,string);return0;}º¯ÊýÃû:strcspn¹¦ÄÜ:ÔÚ´®ÖвéÕÒµÚÒ»¸ö¸ø¶¨×Ö·û¼¯ÄÚÈݵĶÎÓ÷¨:intstrcspn(char*str1,char*str2);³ÌÐòÀý:#includestdio.h#includestring.h#includealloc.hintmain(void){char*string1=1234567890;char*string2=747DC8;intlength;length=strcspn(string1,string2);printf(Characterwherestringsintersectisatposition%d\n,length);return0;}º¯ÊýÃû:strdup¹¦ÄÜ:½«´®¿½±´µ½Ð½¨µÄλÖô¦Ó÷¨:char*strdup(char*str);³ÌÐòÀý:#includestdio.h#includestring.h#includealloc.hintmain(void){char*dup_str,*string=abcde;dup_str=strdup(string);printf(%s\n,dup_str);free(dup_str);return0;}º¯ÊýÃû:stricmp¹¦ÄÜ:ÒÔ´óСд²»Ãô¸Ð·½Ê½±È½ÏÁ½¸ö´®Ó÷¨:intstricmp(char*str1,char*str2);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){char*buf1=BBB,*buf2=bbb;intptr;ptr=stricmp(buf2,buf1);if(ptr0)printf(buffer2isgreaterthanbuffer1\n);if(ptr0)printf(buffer2islessthanbuffer1\n);if(ptr==0)printf(buffer2equalsbuffer1\n);return0;}º¯ÊýÃû:strerror¹¦ÄÜ:·µ»ØÖ¸Ïò´íÎóÐÅÏ¢×Ö·û´®µÄÖ¸ÕëÓ÷¨:char*strerror(interrnum);³ÌÐòÀý:#includestdio.h#includeerrno.hintmain(void){char*buffer;buffer=strerror(errno);printf(Error:%s\n,buffer);return0;}º¯ÊýÃû:strcmpi¹¦ÄÜ:½«Ò»¸ö´®ÓëÁíÒ»¸ö±È½Ï,²»¹Ü´óСдÓ÷¨:intstrcmpi(char*str1,char*str2);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){char*buf1=BBB,*buf2=bbb;intptr;ptr=strcmpi(buf2,buf1);if(ptr0)printf(buffer2isgreaterthanbuffer1\n);if(ptr0)printf(buffer2islessthanbuffer1\n);if(ptr==0)printf(buffer2equalsbuffer1\n);return0;}º¯ÊýÃû:strncmp¹¦ÄÜ:´®±È½ÏÓ÷¨:intstrncmp(char*str1,char*str2,intmaxlen);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){char*buf1=aaabbb,*buf2=bbbccc,*buf3=ccc;intptr;ptr=strncmp(buf2,buf1,3);if(ptr0)printf(buffer2isgreaterthanbuffer1\n);elseprintf(buffer2islessthanbuffer1\n);ptr=strncmp(buf2,buf3,3);if(ptr0)printf(buffer2isgreaterthanbuffer3\n);elseprintf(buffer2islessthanbuffer3\n);return(0);}º¯ÊýÃû:strncmpi¹¦ÄÜ:°Ñ´®ÖеÄÒ»²¿·ÖÓëÁíÒ»´®ÖеÄÒ»²¿·Ö±È½Ï,²»¹Ü´óСдÓ÷¨:intstrncmpi(char*str1,char*str2);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){char*buf1=BBBccc,*buf2=bbbccc;intptr;ptr=strncmpi(buf2,buf1,3);if(ptr0)printf(buffer2isgreaterthanbuffer1\n);if(ptr0)printf(buffer2islessthanbuffer1\n);if(ptr==0)printf(buffer2equalsbuffer1\n);return0;}º¯ÊýÃû:strncpy¹¦ÄÜ:´®¿½±´Ó÷¨:char*strncpy(char*destin,char*source,intmaxlen);³ÌÐòÀý:#includestdio.h#includestring.hintmain(void){charstring[10];char*str1=abcdefghi;strncpy(string,str1,3);string[3]='\0';printf(%s\n,string);return0;}º¯ÊýÃû:strnicmp¹¦ÄÜ:²»×¢ÖØ´óСдµØ±È½ÏÁ½¸ö´®Ó÷¨:intstrnicmp(char*str1,char*str2,unsignedmaxlen);³ÌÐòÀý:#includestring.h#includestdio.hintmain(void){char*buf1=BBBccc,*buf2=bbbccc;intptr;ptr=strnicmp(buf2,buf1,3);if(ptr0)printf(buffer2isgreaterthanbuffer1\n);if(ptr0)printf(buffer2islessthanbuffer1\n);if(ptr==0)printf(buffer2equalsbuffer1\n);return0;}º¯ÊýÃû:strnset¹¦ÄÜ:½«Ò»¸ö´®ÖеÄËùÓÐ×Ö·û¶¼ÉèΪָ¶¨×Ö·ûÓ÷¨:char*strnset(char*str,charch,unsignedn);³ÌÐòÀý:#includestdio.h#includestring.hintmain(void){char*string=abcdefghijklmnopqrstuvwxyz;charletter='x';printf(stringbeforestrnset:%s\n,string);strnset(string,letter,13);printf(stringafterstrnset:%s\n,string);return0;}º¯ÊýÃû:strpbrk¹¦ÄÜ:ÔÚ´®ÖвéÕÒ¸ø¶¨×Ö·û¼¯ÖеÄ×Ö·û
本文标题:C语言字符串函数大全
链接地址:https://www.777doc.com/doc-7028704 .html