'; pr" />

c strchr函数_linux c stdout_strchr函数php(7)

电脑杂谈  发布时间:2017-02-23 21:04:05  来源:网络整理

#include <stdio.h>

int main()

{

char *src="This is the source string";

char dest[50];

char *ptr;

ptr=memccpy(dest,src,'c',strlen(src));

if (ptr)

{

*ptr='\0';

printf("The character was found:%s",dest);

}

else

printf("The character wasn't found");

return 0;

}

@函数名称: memchr

函数原型: void *memchr(const void *s, int c, size_t n)

函数功能: 在字符串中第开始n个字符中寻找某个字符c的位置

函数返回: 返回c的位置指针,返回NULL时表示未找到

参数说明: s-要搜索的字符串,c-要寻找的字符,n-指定长度

所属文件: <string.h>,<mem.h>

#include <string.h>

#include <stdio.h>

int main()

{

char str[17];

char *ptr;

strcpy(str,"This is a string");

ptr=memchr(str,'r',strlen(str));

if (ptr)

printf("The character 'r' is at position: %d",ptr-str);

else

printf("The character was not found");

return 0;

}

@函数名称: memcmp

函数原型: int memcmp(const void *s1, const void *s2,size_t n)

函数功能: 按字典顺序比较两个串s1和s2的前n个字节

函数返回: <0,=0,>0分别表示s1<,=,>s2

参数说明: s1,s2-要比较的字符串,n-比较的长度

所属文件: <string.h>,<mem.h>

#include <stdio.h>

#include <string.h>

int main()

{

char *buf1="ABCDE123";

char *buf2="abcde456";

int stat;

stat=memcmp(buf1,buf2,5);

printf("The strings to position 5 are ");

if(stat) printf("not ");

printf("the same\n");

return 0;

}

@函数名称: memicmp

函数原型: int memicmp(const void *s1, const void *s2, size_t n)

函数功能: 按字典顺序、不考虑字母大小写对字符串s1,s2前n个字符比较

函数返回: <0,=0,>0分别表示s1<,=,>s2

参数说明: s1,s2-要比较的字符串,n-比较的长度

所属文件: <string.h>,<mem.h>

#include <stdio.h>

#include <string.h>

int main()

{

char *buf1="ABCDE123";

char *buf2="abcde456";


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-34103-7.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...