h > < # include stdio。h > < 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 1 \ n"); if (ptr < 0) printf ("buffer 2 ice less than buffer 1 \ n"); if (ptr = = 0) printf ("buffer 2 equals buffer 1 \ n"); return 0; } 函数名: strncpy 功 能: 串拷贝 用 法: char * strncpy (char * destin, char * source, int maxlen); 程序例: # include stdio。
h > < # include string。h > < int main (void) { char string [10]; char * str1 = "abcdefghi"; strncpy (string, str1, 3); string [3] = '\ 0'; printf ("% s" n "string); return 0; } 函数名: strnicmp 功 能: 不注重大小写地比较两个串 用 法: int strnicmp (char * str1, char * str2, unsigned maxlen); 程序例: # include string。h > < # include stdio。h > < int main (void) { char * buf1 = "bbbccc" * buf2 = "bbbccc"; int ptr; ptr = strnicmp (buf2, buf1, 3); if (ptr > 0)。

一个通用表达式是由一些元素组成的.这些元素是通用表达式中最小的匹配单位.一个元素可以是一个字符,例如a,与字符a相匹配,或者是一个特殊字符,例如$,匹配一行的结束.还可以是其他的字符,例如\来匹配一个单词的结束.也就是说要将我们想要查找的字符串放在这两个中间.这样我们就可以精确的来查找我们想要查找的字符串,而不会有其他的一些匹配情况.而如果我们用简单字符串形式来查找,我们就会得到许多的匹配情况,甚至在一个单词中的组成部分也可以成为匹配情况.例如在文件中有californian,unfortunately.如果用命令/for来查找,那么就会找到这两个单词.而如果我们用通用表达式\来进行查找,则只会精确的查找到for,而不会用其他的匹配情况.这时的命令形式如下:。查找任何一个不包含在strcharset串中的字符 (字符串结束符null除外) 在string串中首次出现的位置序号. 返回一个整数值, 指定在string中全部由characters中的字符组成的子串的长度. 如果string以一个不包含在strcharset中的字符开头, 函数将返回0值.。搜索与查找查找函数很多strchr函数,功能也很强大strchr函数,包括了: find rfind find_first_of find_last_of find_first_not_of find_last_not_of这些函数返回符合搜索条件的字符区间内的第一个字符的索引,没找到目标就返回npos。
h > < # include string。h > < int main (void) { char * string1 = "abcdefghijklmnopqrstuvwxyz"; char * string2 = "in"; char * ptr; ptr = strpbrk (string1, string2); if (ptr) printf ("strpbrk found first character:% c \ n" * ptr); else printf ("strpbrk didn't find character in seen \ n"); return 0; } 函数名: strrchr 功 能: 在串中查找指定字符的最后一个出现 用 法: char * strrchr (char * str, char c); 程序例: # include string。h > < # include stdio。h > < 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 ice to position:% d \ n", c, ptr string); else printf ("the character was not found '\ n'); return 0; } 函数名: strrev 功 能: 串倒转 用 法: char * strrev (char * str); 程序例: # include string。
一个通用表达式是由一些元素组成的.这些元素是通用表达式中最小的匹配单位.一个元素可以是一个字符,例如a,与字符a相匹配,或者是一个特殊字符,例如$,匹配一行的结束.还可以是其他的字符,例如\来匹配一个单词的结束.也就是说要将我们想要查找的字符串放在这两个中间.这样我们就可以精确的来查找我们想要查找的字符串,而不会有其他的一些匹配情况.而如果我们用简单字符串形式来查找,我们就会得到许多的匹配情况,甚至在一个单词中的组成部分也可以成为匹配情况.例如在文件中有californian,unfortunately.如果用命令/for来查找,那么就会找到这两个单词.而如果我们用通用表达式\来进行查找,则只会精确的查找到for,而不会用其他的匹配情况.这时的命令形式如下:。查找任何一个不包含在strcharset串中的字符 (字符串结束符null除外) 在string串中首次出现的位置序号. 返回一个整数值, 指定在string中全部由characters中的字符组成的子串的长度. 如果string以一个不包含在strcharset中的字符开头, 函数将返回0值.。请编写一程序,该程序的功能是确定字符串中首次出现的某个字符在串中的位置(即该字符是字符串中的第几个字符),然后从字符串中删除该字符。
h > < # include string。h > < # include alloc。h > < int main (void) { char * string1 = "1234567890"; char * string2 = "123dc8"; int length; length = strspn (string1, string2); printf ("where the character strings differ ice position% d \ n", length); return 0; } 函数名: strstr 功 能: 在串中查找指定字符串的第一次出现 用 法: char * strstr (char * str1, char * str2); 程序例: # include stdio。h > < # include string。h > < int main (void) { char * str1 = "borland international", * str2 = "nation", * ptr; ptr = strstr (str1, str2); printf ("the substring ice:% s \ n", ptr); return 0; } 函数名: strtod 功 能: 将字符串转换为 double 型值 用 法: double strtod (char * str, char * * endptr); 程序例: # include stdio。
h > < # include stdlib。h > < int main (void) { char input [80], * endptr; double value; printf ("enter a floating point number:"); gets (input); value = strtod (input & endptr); printf ("the string ice% s the number ice% lf \ n" input value); return 0; } 函数名: strtok 功 能: 查找由在第二个串中指定的分界符分隔开的单词 用 法: char * strtok (char * str1, char * str2); 程序例: # include string。h > < # include stdio。h > < 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 ('% s' n', p); / * (a second call to strtok using a null as the first parameter returns a pointer two the character following the token * / p = strtok (null, ""); if (p) printf ('% s' n', p); return 0; } 函数名: strtol 功 能: 将串转换为长整数 用 法: long strtol (char * str, char * * endptr, int base); 程序例: # include stdlib。
h > < # include stdio。h > < int main (void) { char * string = "87654321" * endptr; long lnumber; / * strtol converts string two long integer * / lnumber = strtol (string, & endptr, 10); printf ("string =% s long =% ld \ n", string, lnumber); return 0; } 函数名: strupr 功 能: 将串中的小写字母转换为大写字母 用 法: char * strupr (char * str); 程序例: # include stdio。h > < # include string。h > < int main (void) { char * string = "abcdefghijklmnopqrstuvwxyz" * ptr; / * converts string two upper case characters * / ptr = strupr (string); printf ("% s" n ", ptr); return 0; } 函数名: swab 功 能: 交换字节 用 法: void swab (char * from, char *, int nbytes); 程序例: # include stdlib。
h > < # include stdio。h > < # include string。h > < char source [15] = "rfna koblrna d"; char target [15]; int main (void) { swab (source, target, strlen (source)); printf ("this is target:% s \ n", target); return 0; }
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-118073-2.html
这个不是很懂