字符串函数大全
C语言字符串处理函数大全

不错不错.
long strtol( const char *nptr, char **endptr, int base );
long wcstol( const wchar_t *nptr, wchar_t **endptr, int base );
unsigned long strtoul( const char *nptr, char **endptr, int base );
void *memchr( const void *buf, int c, size_t count );
在内存中寻找字符c并返回其地址,如果没有找到,返回NULL
C语言中的字符串操作
char *strcat( char *strDestination, const char *strSource );
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int _mbscmp(const unsigned char *string1, const unsigned char *string2 );
在一个字符串里查找一个字串,返回不包含目标串的长度。注意,好像MSDN上说是第一个strCharSet中任意原子的地方。不知道这样的话还有什么意义。
size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr );
size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr );
C语言字符串函数大全

今天总结了下C语言字符串函数。
C语言字符串函数总结:1.字符处理库(ctype)中的函数2.stdio中的字符串和字符输入/输出的函数3.通用实用库stdlib中的字符串转换函数4.字符串处理库string中的字符串处理函数C语言的字符串实际上是存储单个字符的数组,结尾包含一个结束该字符串的特别的字符("空字符",用'\0'表示)。
char string1[]="first"实际上有6个元素。
char color="blue" char * p="blue"注意p[i]不能修改,若需修改应用字符数组。
一、.字符处理库(ctype)中的函数#include<ctype.h>函数原型:int f(int c)isdigit, isalpha, isalnum, isxdigit, islower, isupper, tolower, toupper, isspace,空白字符:新行符\n, 空格,回车''\r",水平制表符"\t", 垂直制表符"\v" isctrl, ispunct, isprint, isalpha二、stdio中的字符串和字符输入/输出的函数int getchar(void) 从标准输入设备读取字符以整数返回char * get(char * s) 从标准输入设备读入字符到数组s直到遇到新行符和文件结束符为止,然后再数组后追加NULL字符int putchar(int c) 打印字符int puts(const char * s) 打印字符串s和新行符int sprintf(char * s, const char * format) 与printf区别在于输出结果存放在s中int sscanf(char * s, const char * format); 与scanf区别在于从数组s读取数据示例1 字符串反转#include <stdio.h> void reverse(char *s) {if(s[0] == '\0') return;else{reverse(&s[1]); putchar(s[0]);}}int main(){char s[100];gets(s);reverse(s);return 0;}输入:sf输出:fs示例2 sscanf和sprintf #include<stdio.h>int main(){int x=1;double y=2.1;char s[100];sprintf(s,"Hello!%d, %f", x, y);puts(s);sscanf(s,"%d%f",&x,&y);printf("x:%d, y:%f", x, y);return 0;}输出:Hello!1, 2.100000x:1, y:2.100000三、stdlib中的字符串转换函数#include<stdlib.h>1. atoi(将字符串转换成整型数)定义函数int atoi(const char *nptr); 函数说明atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
字符串输入函数

字符串输入函数
这里提供几种常用的字符串输入函数:
1. scanf函数:scanf函数可以用来输入字符串,格式为"%s"。
例如:
c
char str[20];
scanf("%s", str);
2. gets函数:gets函数可以读取一行字符串,但不推荐使用,因为它无法防止缓冲区溢出。
例如:
c
char str[20];
gets(str);
3. fgets函数:fgets函数可以读取一行字符串,且安全可靠,因为它可以指定缓冲区的大小。
例如:
c
char str[20];
fgets(str, 20, stdin);
4. getline函数:getline函数可以动态分配内存空间,以适应不同的字符串长度。
例如:
c
char* str = NULL;
size_t len = 0;
getline(&str, &len, stdin);
注意:使用getline函数时,需要手动释放分配的内存空间,否则会发生内存泄漏。
可以使用free函数释放内存空间:
c
free(str);。
字符串类型转换函数

字符串类型转换函数在Python中,有几个内置的函数可以用来进行字符串类型的转换。
以下是一些常用的字符串类型转换函数:1. str():将其他类型的数据转换为字符串类型。
示例:```pythonnum = 10num_str = str(num)print(num_str) # 输出结果为 "10"```2. int():将字符串或其他数据类型转换为整数类型。
示例:```pythonnum_str = "10"num = int(num_str) # 将字符串 "10" 转换为整数类型print(num) # 输出结果为 10```3. float():将字符串或其他数据类型转换为浮点数类型。
示例:```pythonnum_str = "10.5"num = float(num_str) # 将字符串 "10.5" 转换为浮点数类型 print(num) # 输出结果为 10.5```4. bool():将字符串或其他数据类型转换为布尔类型。
示例:```pythonstr_true = "True"bool_true = bool(str_true) # 将字符串 "True" 转换为布尔值Trueprint(bool_true) # 输出结果为 Truezero = 0bool_zero = bool(zero) # 将整数 0 转换为布尔值 Falseprint(bool_zero) # 输出结果为 False```这些函数可以帮助你在需要时进行字符串类型和其他类型之间的转换。
字符串函数大全

函数名: stpcpy功能: 拷贝一个字符串到另一个用法: char *stpcpy(char *destin, char *source); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";stpcpy(string, str1);printf("%s\n", string);return 0;}函数名: strcat功能: 字符串拼接函数用法: char *strcat(char *destin, char *source); 程序例:#include <string.h>#include <stdio.h>int main(void){char destination[25];char *blank = " ", *c = "C++", *Borland = "Borland"; strcpy(destination, Borland);strcat(destination, blank);strcat(destination, c);printf("%s\n", destination);return 0;}函数名: strchr功能: 在一个串中查找给定字符的第一个匹配之处\用法: char *strchr(char *str, char c);程序例:#include <string.h>#include <stdio.h>{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: %d\n", c, ptr-string);elseprintf("The character was not found\n");return 0;}函数名: strcmp功能: 串比较用法: int strcmp(char *str1, char *str2);看Asic码,str1>str2,返回值 > 0;两串相等,返回0程序例:#include <string.h>#include <stdio.h>{char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";int ptr;ptr = strcmp(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");elseprintf("buffer 2 is less than buffer 1\n");ptr = strcmp(buf2, buf3);if (ptr > 0)printf("buffer 2 is greater than buffer 3\n");elseprintf("buffer 2 is less than buffer 3\n");return 0;}函数名: strncmpi功能: 将一个串中的一部分与另一个串比较, 不管大小写用法: int strncmpi(char *str1, char *str2, unsigned maxlen); 程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = strcmpi(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n"); if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strcpy功能: 串拷贝用法: char *strcpy(char *str1, char *str2); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";strcpy(string, str1);printf("%s\n", string);return 0;}函数名: strcspn功能: 在串中查找第一个给定字符集内容的段用法: int strcspn(char *str1, char *str2); 程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *string1 = "1234567890";char *string2 = "747DC8";int length;length = strcspn(string1, string2);printf("Character where strings intersect is at position %d\n", length);return 0;}函数名: strdup功能: 将串拷贝到新建的位置处用法: char *strdup(char *str);程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *dup_str, *string = "abcde";dup_str = strdup(string);printf("%s\n", dup_str);free(dup_str);return 0;}函数名: stricmp功能: 以大小写不敏感方式比较两个串用法: int stricmp(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = stricmp(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");if (ptr < 0)printf("buffer 2 is less than buffer 1\n"); if (ptr == 0)printf("buffer 2 equals buffer 1\n"); return 0;}函数名: strerror功能: 返回指向错误信息字符串的指针用法: char *strerror(int errnum);程序例:#include <stdio.h>#include <errno.h>int main(void){char *buffer;buffer = strerror(errno);printf("Error: %s\n", buffer);return 0;}函数名: strcmpi功能: 将一个串与另一个比较, 不管大小写用法: int strcmpi(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = strcmpi(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n"); if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strncmp功能: 串比较用法: int strncmp(char *str1, char *str2, int maxlen);程序例:#include <string.h>#include <stdio.h>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 1\n");elseprintf("buffer 2 is less than buffer 1\n");ptr = strncmp(buf2,buf3,3);if (ptr > 0)printf("buffer 2 is greater than buffer 3\n");elseprintf("buffer 2 is less than buffer 3\n");return(0);}函数名: strncmpi功能: 把串中的一部分与另一串中的一部分比较, 不管大小写用法: int strncmpi(char *str1, char *str2);程序例:#include <string.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 is 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)printf("buffer 2 is greater than buffer 1\n");if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strnset功能: 将一个串中的所有字符都设为指定字符用法: char *strnset(char *str, char ch, unsigned n); 程序例:#include <stdio.h>#include <string.h>int main(void){char *string = "abcdefghijklmnopqrstuvwxyz";char letter = 'x';printf("string before strnset: %s\n", string);strnset(string, letter, 13);printf("string after strnset: %s\n", string);return 0;}函数名: strpbrk功能: 在串中查找给定字符集中的字符用法: char *strpbrk(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>int main(void){char *string1 = "abcdefghijklmnopqrstuvwxyz";char *string2 = "onm";char *ptr;ptr = strpbrk(string1, string2);if (ptr)printf("strpbrk found first character: %c\n", *ptr); elseprintf("strpbrk didn't find character in set\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 is at position: %d\n", c, ptr-string); elseprintf("The character was not found\n");return 0;}函数名: strrev功能: 串倒转用法: char *strrev(char *str);程序例:#include <string.h>#include <stdio.h>int main(void){char *forward = "string";printf("Before strrev(): %s\n", forward); strrev(forward);printf("After strrev(): %s\n", forward); return 0;}函数名: strset功能: 将一个串中的所有字符都设为指定字符用法: char *strset(char *str, char c);程序例:#include <stdio.h>#include <string.h>int main(void){char string[10] = "123456789";char symbol = 'c';printf("Before strset(): %s\n", string);strset(string, symbol);printf("After strset(): %s\n", string);return 0;}函数名: strspn功能: 在串中查找指定字符集的子集的第一次出现用法: int strspn(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *string1 = "1234567890";char *string2 = "123DC8";int length;length = strspn(string1, string2);printf("Character where strings differ is at 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 is: %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 is %s the number is %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 terminatorin front of the token, if found */p = strtok(input, ",");if (p) printf("%s\n", p);/* A second call to strtok using a NULLas the first parameter returns a pointerto 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 to 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 to upper case characters */ptr = strupr(string);printf("%s\n", ptr);return 0;}函数名: swab功能: 交换字节用法: void swab (char *from, char *to, 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;}。
8种C语言基本常用的字符串处理函数

8种C语言基本常用的字符串处理函数8种C语言基本常用的字符串处理函数本文是店铺搜索整理的8种基本的常用的字符串处理函数,所有的C语言编译系统中一般都提供这些函数,以下是店铺为大家整理的8种C语言基本常用的字符串处理函数,仅供参考,希望能够帮助到大家。
1、puts函数——输出字符串的函数一般的形式为puts(字符串组)作用:将一个字符串输出到终端。
如,char一个string,并赋予初值。
调用puts(string);进行字符串的输出。
2、gets函数——输入字符串的函数一般的形式:gets(字符数组)作用:从终端输入一个字符串到字符数组,并且得到一个函数值成为字符数组的起始地址。
gets(str);键盘输入,,,,你懂得。
注意:puts和gets函数只能输出或者输入一个字符串。
3、strcat函数——字符串连接函数一般的形式:strcat(字符数组1,字符数组2);作用:把两个字符串数组中字符串连接起来,把字符串2连接到字符串1的后面。
说明:字符数组1必须足够大,以便容纳连接后的新字符串。
4、strcpy/strncpy函数——字符串复制函数一般形式:strcpy(字符数组1,字符串2);作用:将字符串2复制到字符数组1中去。
如:char str1[10],str2[]="DongTeng";strcpy(str1,str2);执行后的结果为:你懂得注意:1. 不能用赋值语句直接将一个字符串常量或者字符数组直接给一个字符数组。
2. 用strncpy可以赋值指定的位置的字符。
strncpy(str1,str2,3);将str2中的第3个字符复制到str1中。
5、strcmp函数——字符串比较函数一般形式:strcmp(字符串1,字符串2);作用:用来比较两个字符串的差异。
具有不同的比较规则。
6、strlen函数——测字符串长度的函数一般形式:strlen(字符数组);如:char str[10]="DongTeng";printf("%d",strlen(str));得到的结果是:57、strlwr函数——转换为小写的函数一般形式:strlwr(字符串);8、strupr函数——转换为大写的函数一般形式:strupr(字符串)。
PGSQL关于字符串的各种函数

PGSQL关于字符串的各种函数1、计算字符串字符数和字符串长度的函数:char_length(str)和length(str)char_length(str)返回值为字符串str所包含的字符个数。
⼀个多字节字符算作⼀个单字符。
例⼦:使⽤char_length函数计算字符串字符个数,如:length(str)返回值为字符串的字节长度,使⽤utf8编码字符集时,⼀个汉字是3字节,⼀个数字或字母算⼀个字节。
注意:length函数的计算结果和char_length函数相同,因为英⽂字符的个数和所占字节相同,⼀个字符占⼀个字节。
2、合并字符串函数:concat(s1,s2,,,,)、concat_ws(x,s1,s2,,,,)concat(s1,s2,,,)返回结果为连接参数产⽣的字符串。
任何⼀个参数为null,返回值就为null。
如果所有参数为⾮⼆进制字符串,那么结果为⾮⼆进制字符串。
如果⾃变量中含有任⼀⼆进制字符串,那么结果就为⼀个⼆进制字符串。
concat_ws(x,s1,s2,,,)x是与其他参数的分隔符。
例⼦:使⽤concat函数连接字符串,如下:例⼦:使⽤concat_ws函数连接带分隔符的字符串,如:3、获取指定长度的字符串的函数:left(s,n)和right(s,n)left(s,n)返回字符串s开始的最左边n个字符。
例⼦:使⽤left函数返回字符串中左边开始的5个字符,如right(s,n)返回字符串s最右边个字符例⼦:使⽤right函数返回字符串中右边的字符,如:4、填充字符串的函数:lpad(s1,len,s2)和rpad(s1,len,s2)lpad(s1,len,s2)返回字符串s1,其左边由字符s2填充,填充长度为len,假如s1的长度⼤于len,则返回值被缩短⾄len字符。
例⼦:使⽤lpad函数对字符串进⾏填充操作,如下:rpad(s1,len,s2)返回字符串s1,其右边被字符串s2填补⾄len字符长度。
C++中字符串常用的函数

C++中字符串常⽤的函数⼀、字符串函数strlen原型:extern int strlen(char *s);⽤法:#include <string.h> 功能:计算字符串s的长度说明:返回s的长度,不包括结束符NULL。
strcmp 原型:extern int strcmp(char *s1,char * s2);⽤法:#include <string.h> 功能:⽐较字符串s1和s2⼤⼩(ascii码值),区分⼤⼩写。
说明:当s1<s2时,返回值<0当s1=s2时,返回值=0当s1>s2时,返回值>0strcpy 原型:extern char *strcpy(char *dest,char *src);⽤法:#include <string.h>功能:把src所指由NULL结束的字符串复制到dest所指的数组中。
说明:src和dest所指内存区域不可以重叠且dest必须有⾜够的空间来容纳src的字符串。
返回指向dest的指针。
fabs(x) --------- 计算x的绝对值。
sqrt(x) --------- 计算x的开⽅。
isalpha(c) 检查字符c是否为字母。
是则函数返回值为1;不是则函数返回值为0。
alpha是单词“alphabet”的前5个字母。
isalnum(c) 检查字符c是否为字母或数字。
是则函数返回值为1;不是则函数返回值为0。
alnum是单词alphabet 和单词number 的缩写。
memset原型:extern void *memset(void *buffer, int c, int count);⽤法:#include <string.h>功能:把buffer所指内存区域的前count个字节设置成字符c。
说明:返回指向buffer的指针。
stricmp,strcmpi 原型:extern int stricmp(char *s1,char * s2);⽤法:#include <string.h>功能:⽐较字符串s1和s2,但不区分字母的⼤⼩写。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
printf("buffer 2 is greater than buffer 1\n"); if (ptr < 0)
printf("buffer 2 is less than buffer 1\n"); if (ptr == 0)
-------------------------------------------------------
函数名: strcspn
功 能: 在串中查找第一个给定字符集内容的段
用 法: int strcspn(char *str1, char *str2);
程序例:Biblioteka #include <stdio.h>
{ char *dup_str, *string = "abcde"; dup_str = strdup(string); printf("%s\n", dup_str); free(dup_str); return 0;
}
-------------------------------------------------------
printf("Character where strings intersect is at position %d\n", length);
return 0;
第3页
C++字符串函数大全.txt }
------------------------------------------------------函数名: strdup 功 能: 将串拷贝到新建的位置处 用 法: char *strdup(char *str); 程序例: #include <stdio.h> #include <string.h> #include <alloc.h> int main(void)
char *buf1 = "BBBccc", *buf2 = "bbbccc"; int ptr; ptr = strnicmp(buf2, buf1, 3); if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); if (ptr < 0)
功 能: 不注重大小写地比较两个串
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
程序例:
#include <string.h>
第9页
C++字符串函数大全.txt #include <stdio.h> int main(void) {
printf("buffer 2 is less than buffer 1\n");
第7页
C++字符串函数大全.txt ptr = strncmp(buf2,buf3,3); if (ptr > 0)
printf("buffer 2 is greater than buffer 3\n"); else
第1页
C++字符串函数大全.txt {
char *buf1 = "BBB", *buf2 = "bbb"; int ptr; ptr = strcmpi(buf2, buf1); if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); if (ptr < 0)
-------------------------------------------------------
函数名: strcmp 功 char *a = "aaa"; char *b = "bbb"; int c; c = strcmp(a, b);
能: 串比较
-------------------------------------------------------
程序例:
#include <stdio.h>
第5页
C++字符串函数大全.txt #include <errno.h> int main(void) {
char *buffer; buffer = strerror(errno); printf("Error: %s\n", buffer); return 0; }
printf("buffer 2 is less than buffer 3\n"); return(0); } ------------------------------------------------------函数名: strncmpi 功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 用 法: int strncmpi(char *str1, char *str2); 程序例: #include <string.h> #include <stdio.h> int main(void) { char *buf1 = "BBBccc", *buf2 = "bbbccc"; int ptr; ptr = strncmpi(buf2,buf1,3); if (ptr > 0)
函数名: stricmp 功 能: 以大小写不敏感方式比较两个串
第4页
C++字符串函数大全.txt 用 法: int stricmp(char *str1, char *str2); 程序例: #include <string.h> #include <stdio.h> int main(void) {
char *buf1 = "BBB", *buf2 = "bbb"; int ptr; ptr = strcmpi(buf2, buf1); if (ptr > 0)
printf("buffer 2 is greater than buffer 1\n"); 第6页
C++字符串函数大全.txt if (ptr < 0)
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
#include <string.h>
#include <alloc.h>
int main(void)
{
char *string1 = "1234567890";
char *string2 = "747DC8";
int length;
length = strcspn(string1, string2);
C++字符串函数大全.txt 函数名: strcpy 功能: 拷贝一个字符串到另一个 char string[10]; char *str1 = "abcdefghi"; strcpy(string, str1); strcpy(des, src+4, strlen(src+4)); ------------------------------------------------------函数名: strcat 功 能: 字符串拼接函数 char destination[25]; char *Borland = "Borland"; strcpy(destination, Borland); ------------------------------------------------------函数名: strchr 功 能: 在一个串中查找给定字符的第一个匹配之处\ char a[15]="abc"; char *b; b=strchr(a,'b');
printf("buffer 2 is less than buffer 1\n"); if (ptr == 0)
函数名: strcpy
功 能: 串拷贝
用 法: char *strcpy(char *str1, char *str2);
程序例:
#include <stdio.h>
#include <string.h>