日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C語言字符串函數(shù)集錦(二)

說起字符串函數(shù),我想大家都不陌生。字符串函數(shù)對二進(jìn)制數(shù)據(jù)、字符串和表達(dá)式執(zhí)行不同的運算。下面總結(jié)了C語言中的字符串函數(shù)。

發(fā)展壯大離不開廣大客戶長期以來的信賴與支持,我們將始終秉承“誠信為本、服務(wù)至上”的服務(wù)理念,堅持“二合一”的優(yōu)良服務(wù)模式,真誠服務(wù)每家企業(yè),認(rèn)真做好每個細(xì)節(jié),不斷完善自我,成就企業(yè),實現(xiàn)共贏。行業(yè)涉及報廢汽車回收等,在網(wǎng)站建設(shè)、成都全網(wǎng)營銷、WAP手機網(wǎng)站、VI設(shè)計、軟件開發(fā)等項目上具有豐富的設(shè)計經(jīng)驗。

13、函數(shù)名: strncmpi

功 能: 把串中的一部分與另一串中的一部分比較, 不管大小寫

用 法:

 
 
  1. int strncmpi(char *str1, char *str2);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *buf1 = "BBBccc", *buf2 = "bbbccc";   
  6. int ptr;   
  7. ptr = strncmpi(buf2,buf1,3);   
  8. if (ptr > 0)   
  9. printf("buffer 2 is greater than buffer 1\n");   
  10. if (ptr < 0)   
  11. printf("buffer 2 is less than buffer 1\n");   
  12. if (ptr == 0)   
  13. printf("buffer 2 equals buffer 1\n");   
  14. return 0;   
  15. }  

 

14、函數(shù)名: strncpy

功 能: 串拷貝

用 法:

 
 
  1. char *strncpy(char *destin, char *source, int maxlen);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char string[10];   
  6. char *str1 = "abcdefghi";   
  7. strncpy(string, str1, 3);   
  8. string[3] = '\0';   
  9. printf("%s\n", string);   
  10. return 0;   
  11. }  

 

15、函數(shù)名: strnicmp

功 能: 不注重大小寫地比較兩個串

用 法:

 
 
  1. int strnicmp(char *str1, char *str2, unsigned maxlen);  

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *buf1 = "BBBccc", *buf2 = "bbbccc";   
  6. int ptr;   
  7. ptr = strnicmp(buf2, buf1, 3);   
  8. if (ptr > 0)   
  9. printf("buffer 2 is greater than buffer 1\n");   
  10. if (ptr < 0)   
  11. printf("buffer 2 is less than buffer 1\n");   
  12. if (ptr == 0)   
  13. printf("buffer 2 equals buffer 1\n");   
  14. return 0;   
  15. }  

 

16、函數(shù)名: strnset

功 能: 將一個串中的所有字符都設(shè)為指定字符

用 法:

 
 
  1. char *strnset(char *str, char ch, unsigned n);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *string = "abcdefghijklmnopqrstuvwxyz";   
  6. char letter = 'x';   
  7. printf("string before strnset: %s\n", string);   
  8. strnset(string, letter, 13);   
  9. printf("string after strnset: %s\n", string);   
  10. return 0;   
  11. }  

 

17、函數(shù)名: strpbrk

功 能: 在串中查找給定字符集中的字符

用 法:

 
 
  1. char *strpbrk(char *str1, char *str2);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *string1 = "abcdefghijklmnopqrstuvwxyz";   
  6. char *string2 = "onm";   
  7. char *ptr;   
  8. ptr = strpbrk(string1, string2);   
  9. if (ptr)   
  10. printf("strpbrk found first character: %c\n", *ptr);   
  11. else   
  12. printf("strpbrk didn't find character in set\n");   
  13. return 0;   
  14. }  

 

18、函數(shù)名: strrchr

功 能: 在串中查找指定字符的最后一個出現(xiàn)

用 法:

 
 
  1. char *strrchr(char *str, char c);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3.  
  4. int main(void)   
  5. {   
  6. char string[15];   
  7. char *ptr, c = 'r';   
  8.  
  9. strcpy(string, "This is a string");   
  10. ptr = strrchr(string, c);   
  11. if (ptr)   
  12. printf("The character %c is at position: %d\n", c, ptr-string);   
  13. else   
  14. printf("The character was not found\n");   
  15. return 0;   
  16. }  

 

19、函數(shù)名: strrev

功 能: 串倒轉(zhuǎn)

用 法:

char *strrev(char *str);

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *forward = "string";   
  6. printf("Before strrev(): %s\n", forward);   
  7. strrev(forward);   
  8. printf("After strrev(): %s\n", forward);   
  9. return 0;   
  10. }  

 

#p#

20、函數(shù)名: strset

功 能: 將一個串中的所有字符都設(shè)為指定字符

用 法:

 
 
  1. char *strset(char *str, char c);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char string[10] = "123456789";   
  6. char symbol = 'c';   
  7. printf("Before strset(): %s\n", string);   
  8. strset(string, symbol);   
  9. printf("After strset(): %s\n", string);   
  10. return 0;   
  11. }  

 

21、函數(shù)名: strspn

功 能: 在串中查找指定字符集的子集的第一次出現(xiàn)

用 法:

 
 
  1. int strspn(char *str1, char *str2);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. #include    
  4. int main(void)   
  5. {   
  6. char *string1 = "1234567890";   
  7. char *string2 = "123DC8";   
  8. int length;   
  9. length = strspn(string1, string2);   
  10. printf("Character where strings differ is at position %d\n", length);   
  11. return 0;   
  12. }  

 

22、函數(shù)名: strstr

功 能: 在串中查找指定字符串的第一次出現(xiàn)

用 法:

 
 
  1. char *strstr(char *str1, char *str2);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *str1 = "Borland International", *str2 = "nation", *ptr;   
  6. ptr = strstr(str1, str2);   
  7. printf("The substring is: %s\n", ptr);   
  8. return 0;   
  9. }  

 

23、函數(shù)名: strtod

功 能: 將字符串轉(zhuǎn)換為double型值

用 法:

 
 
  1. double strtod(char *str, char **endptr);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char input[80], *endptr;   
  6. double value;   
  7. printf("Enter a floating point number:");   
  8. gets(input);   
  9. value = strtod(input, &endptr);   
  10. printf("The string is %s the number is %lf\n", input, value);   
  11. return 0;   
  12. }  

 

24、函數(shù)名: strtok

功 能: 查找由在第二個串中指定的分界符分隔開的單詞

用 法:

 
 
  1. char *strtok(char *str1, char *str2);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char input[16] = "abc,d";   
  6. char *p;   
  7. /* strtok places a NULL terminator   
  8. in front of the token, if found */   
  9. p = strtok(input, ",");   
  10. if (p) printf("%s\n", p);   
  11. /* A second call to strtok using a NULL   
  12. as the first parameter returns a pointer   
  13. to the character following the token */   
  14. p = strtok(NULL, ",");   
  15. if (p) printf("%s\n", p);   
  16. return 0;   
  17. }  

25、函數(shù)名: strtol

功 能: 將串轉(zhuǎn)換為長整數(shù)

用 法:

 
 
  1. long strtol(char *str, char **endptr, int base);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *string = "87654321", *endptr;   
  6. long lnumber;   
  7. /* strtol converts string to long integer */   
  8. lnumber = strtol(string, &endptr, 10);   
  9. printf("string = %s long = %ld\n", string, lnumber);   
  10. return 0;   
  11. }  

 

26、函數(shù)名: strupr

功 能: 將串中的小寫字母轉(zhuǎn)換為大寫字母

用 法:

 
 
  1. char *strupr(char *str);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. int main(void)   
  4. {   
  5. char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;   
  6. /* converts string to upper case characters */   
  7. ptr = strupr(string);   
  8. printf("%s\n", ptr);   
  9. return 0;   
  10. }  

 

27、函數(shù)名: swab

功 能: 交換字節(jié)

用 法:

 
 
  1. void swab (char *from, char *to, int nbytes);  

 

程序例:

 
 
  1. #include    
  2. #include    
  3. #include    
  4. char source[15] = "rFna koBlrna d";   
  5. char target[15];   
  6. int main(void)   
  7. {   
  8. swab(source, target, strlen(source));   
  9. printf("This is target: %s\n", target);   
  10. return 0;   

到這,關(guān)于字符串函數(shù)的介紹就給大家介紹完了。希望對你有幫助。


網(wǎng)站名稱:C語言字符串函數(shù)集錦(二)
網(wǎng)頁地址:http://www.dlmjj.cn/article/dhgcodi.html