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

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

函数功能: 找出str指向的字符串中第一次出现字符ch的位置

函数返回: 返回指向该位置的指针,如找不到,则返回空指针

参数说明: str-待搜索的字符串,ch-查找的字符

所属文件: <string.h>

#include <string.h>

#include <stdio.h>

int main()

{

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);

else

printf("The character was not found\n");

return 0;

}

@函数名称: strrchr

函数原型: char *strrchr(const char *s, int c)

函数功能: 得到字符串s中最后一个含有c字符的位置指针

函数返回: 位置指针

参数说明:

所属文件: <string.h>

#include <string.h>

#include <stdio.h>

int main()

{

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",c,ptr-string);

else

printf("The character was not found");

return 0;

}

@函数名称: strstr

函数原型: char* strstr(char* str1,char* str2);

函数功能: 找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)

函数返回: 返回该位置的指针,如找不到,返回空指针

参数说明:

所属文件: <string.h>

#include <stdio.h>

#include <string.h>

int main()

{

char *str1="Open Watcom C/C++",*str2="Watcom",*ptr;

ptr=strstr(str1,str2);

printf("The substring is:%s\n",ptr);

return 0;

}

@函数名称: strrev

函数原型: char *strrev(char *s)

函数功能: 将字符串中的所有字符颠倒次序排列

函数返回: 指向s的指针

参数说明:

所属文件: <string.h>

#include <string.h>

#include <stdio.h>

int main()

{

char *forward="string";

printf("Before strrev():%s",forward);

strrev(forward);

printf("After strrev(): %s",forward);

return 0;

}

@函数名称: strnset

函数原型: char *strnset(char *s, int ch, size_t n)


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

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

    • 房卡
      房卡

      保卫家园

      • 常佳欣
        常佳欣

        不过他这招如果用在另外一个大国面前应该会凑效

    • 谭文龙
      谭文龙

      这种东西还用酿吗

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