函数名: strchr 功能: 在一个串中查找给定字符的第一个匹配之处 用法: char *strchr(char *str, char c); 程序例: #include #include int main(void) { char string[15]; char *ptr, c = 'r'; strcpy(string, This is a string); ptr = strchr(string, c); if (ptr) printf(The character %c is at position: %dn, c, ptr-string); else printf(The character was not foundn); return 0; }
函数名: strncmpi 功能: 将一个串中的一部分与另一个串比较, 不管大小写 用法: int strncmpi(char *str1, char *str2, unsigned maxlen); 程序例: #include #include int main(void) { char *buf1 = BBB, *buf2 = bbb; int ptr; ptr = strcmpi(buf2, buf1); if (ptr > 0) printf(buffer 2 is greater than buffer 1n); if (ptr < 0) printf(buffer 2 is less than buffer 1n); if (ptr == 0) printf(buffer 2 equals buffer 1n); return 0; }
函数名: strcspn 功能: 在串中查找第一个给定字符集内容的段 用法: int strcspn(char *str1, char *str2); 程序例: #include #include #include int main(void) { char *string1 = 1234567890; char *string2 = 747DC8; int length; length = strcspn(string1, string2); printf(Character where strings intersect is at position %dn, length); return 0; }
函数名: strcmpi 功能: 将一个串与另一个比较, 不管大小写 用法: int strcmpi(char *str1, char *str2); 程序例: #include #include int main(void) { char *buf1 = BBB, *buf2 = bbb; int ptr; ptr = strcmpi(buf2, buf1); if (ptr > 0) printf(buffer 2 is greater than buffer 1n); if (ptr < 0) printf(buffer 2 is less than buffer 1n); if (ptr == 0) printf(buffer 2 equals buffer 1n); return 0; }
函数名: strncmp 功能: 串比较 用法: int strncmp(char *str1, char *str2, int maxlen); 程序例: #include #include int main(void) { char *buf1 = aaabbb, *buf2 = bbbccc, *buf3 = ccc; int ptr; ptr = strncmp(buf2,buf1,3); if (ptr > 0) printf(buffer 2 is greater than buffer 1n); else printf(buffer 2 is less than buffer 1n); ptr = strncmp(buf2,buf3,3); if (ptr > 0) printf(buffer 2 is greater than buffer 3n); else printf(buffer 2 is less than buffer 3n); return(0); }
函数名: strncmpi 功能: 把串中的一部分与另一串中的一部分比较, 不管大小写 用法: int strncmpi(char *str1, char *str2); 程序例: #include #include int main(void) { char *buf1 = BBBccc, *buf2 = bbbccc; int ptr; ptr = strncmpi(buf2,buf1,3); if (ptr > 0) printf(buffer 2 is greater than buffer 1n); if (ptr < 0) printf(buffer 2 is less than buffer 1n); if (ptr == 0) printf(buffer 2 equals buffer 1n); return 0; }
函数名: strpbrk 功能: 在串中查找给定字符集中的字符 用法: char *strpbrk(char *str1, char *str2); 程序例: #include #include int main(void) { char *string1 = abcdefghijklmnopqrstuvwxyz; char *string2 = onm; char *ptr; ptr = strpbrk(string1, string2); if (ptr) printf(strpbrk found first character: %cn, *ptr); else printf(strpbrk didn't find character in setn); return 0; }
函数名: strrchr 功能: 在串中查找指定字符的最后一个出现 用法: char *strrchr(char *str, char c); 程序例: #include #include int main(void) { char string[15]; char *ptr, c = 'r'; strcpy(string, This is a string); ptr = strrchr(string, c); if (ptr) printf(The character %c is at position: %dn, c, ptr-string); else printf(The character was not foundn); return 0; }
函数名: strtod 功能: 将字符串转换为double型值 用法: double strtod(char *str, char **endptr); 程序例: #include #include int main(void) { char input[80], *endptr; double value; printf(Enter a floating point number:); gets(input); value = strtod(input, &endptr); printf(The string is %s the number is %lfn, input, value); return 0; }
函数名: strtok 功能: 查找由在第二个串中指定的分界符分隔开的单词 用法: char *strtok(char *str1, char *str2); 程序例: #include #include int main(void) { char input[16] = abc,d; char *p; /* strtok places a NULL terminator in front of the token, if found */ p = strtok(input, ,); if (p) printf(%sn, p); /* A second call to strtok using a NULL as the first parameter returns a pointer to the character following the token */ p = strtok(NULL, ,); if (p) printf(%sn, p); return 0; }
函数名: strtol 功能: 将串转换为长整数 用法: long strtol(char *str, char **endptr, int base); 程序例: #include #include int main(void) { char *string = 87654321, *endptr; long lnumber; /* strtol converts string to long integer */ lnumber = strtol(string, &endptr, 10); printf(string = %s long = %ldn, string, lnumber); return 0; } 函数名: strupr 功能: 将串中的小写字母转换为大写字母 用法: char *strupr(char *str); 程序例: #include #include int main(void) { char *string = abcdefghijklmnopqrstuvwxyz, *ptr; /* converts string to upper case characters */ ptr = strupr(string); printf(%sn, ptr); return 0; }