strstr函数头文件_strstr函数[通俗易懂]

strstr函数头文件_strstr函数[通俗易懂]函数名:strstr功能:在串中查找指定字符串的第一次出现用法:char*strstr(char*str1,char*str2);程序例:#include#includeintmain(void){char*str1=”BorlandInternational”,*str2=”nation”,*ptr;ptr=strstr(str1,str2);print…

大家好,又见面了,我是你们的朋友全栈君。

函数名: strstr

功 能: 在串中查找指定字符串的第一次出现

用 法: char *strstr(char *str1, char *str2);

程序例:

#include

#include

int main(void)

{

char *str1 = “Borland

International”, *str2 = “nation”, *ptr;

ptr = strstr(str1,

str2);

printf(“The substring is:

%s\n”, ptr);

return 0;

}

函数名: stpcpy

功 能: 拷贝一个字符串到另一个

用 法: char *stpcpy(char *destin, char *source);

程序例:

#include

#include

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

#include

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

#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: %d\n”, c,

ptr-string);

else

printf(“The character was not found\n”);

return

0;

}

函数名: strcmp

功 能: 串比较

用 法: int strcmp(char *str1, char *str2);

看Asic码,str1>str2,返回值 >

0;两串相等,返回0

程序例:

#include

#include

int main(void)

{

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

else

printf(“buffer 2 is less than buffer 1\n”);

ptr =

strcmp(buf2, buf3);

if (ptr

> 0)

printf(“buffer 2 is greater than buffer 3\n”);

else

printf(“buffer 2 is less than buffer 3\n”);

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

#include

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

#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 %d\n”,

length);

return

0;

}

函数名: strdup

功 能: 将串拷贝到新建的位置处

用 法: char *strdup(char *str);

程序例:

#include

#include

#include

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

#include

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

#include

int main(void)

{

char *buffer;

buffer =

strerror(errno);

printf(“Error: %s\n”,

buffer);

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

#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 1\n”);

else

printf(“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”);

else

printf(“buffer 2 is less than buffer 3\n”);

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

#include

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

#include

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

#include

int main(void)

{

char string[50] =

“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

#include

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

else

printf(“strpbrk didn’t find character in set\n”);

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: %d\n”, c,

ptr-string);

else

printf(“The character was not found\n”);

return 0;

}

函数名: strrev

功 能: 串倒转

用 法: char *strrev(char *str);

程序例:

#include

#include

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

#include

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

#include

#include

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;

}

函数名: 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 %lf\n”, input, value);

return 0;

}

函数名: strtok

功 能: 查找由在第二个串中指定的分界符分隔开的单词

用 法: char *strtok(char *str1, char *str2);

程序例:

#include

#include

int main(void)

{

char input[16] =

“abc,d”;

char *p;

p = strtok(input, “,”);

if

(p) printf(“%s\n”, p);

p = strtok(NULL, “,”);

if

(p) printf(“%s\n”, p);

return 0;

}

函数名: strtol

功 能: 将串转换为长整数

用 法: long strtol(char *str, char **endptr, int base);

程序例:

#include

#include

int main(void)

{

char *string = “87654321”,

*endptr;

long lnumber;

lnumber = strtol(string,

&endptr, 10);

printf(“string = %s long =

%ld\n”, string, lnumber);

return 0;

}

函数名: strupr

功 能: 将串中的小写字母转换为大写字母

用 法: char *strupr(char *str);

程序例:

#include

#include

int main(void)

{

char *string =

“abcdefghijklmnopqrstuvwxyz”, *ptr;

ptr = strupr(string);

printf(“%s\n”, ptr);

return 0;

}

函数名: swab

功 能: 交换字节

用 法: void swab (char *from, char *to, int nbytes);

程序例:

#include

#include

#include

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;

原型:extern char *strstr(char *haystack, char *needle);

strstr函数头文件_strstr函数[通俗易懂]

所在头文件:#include

strstr函数头文件_strstr函数[通俗易懂]

功能:从字符串haystack中寻找needle第一次出现的位置(不比较结束符NULL)。

strstr函数头文件_strstr函数[通俗易懂]

说明:返回指向第一次出现needle位置的指针,如果没找到则返回NULL。

strstr函数头文件_strstr函数[通俗易懂]具体使用例子:

#include

#include

int main(int argc,char **argv)

{

char *haystack=”aaa||a||bbb||c||ee||”;

char *needle=”||”;

char*

buf = strstr(

haystack, needle);

while( buf

!= NULL )

{

buf[0]=’\0′;

printf( “%s\n

“, haystack);

haystack = buf

+ strlen(needle);

buf = strstr(

haystack, needle);

}

return 0;

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/152967.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • tomcat java_tomcat和maven的区别

    tomcat java_tomcat和maven的区别缓存什么是缓存[Cache]存在内存中的临时数据将用户经常查询的数据放在缓存(内存)中,用户去查询数据的时候就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高查询效率,解决了高并发系统的性能问题。为什么使用缓存减少和数据库的数据交换次数,较少系统开销,提高系统效率什么样的数据库能使用缓存经常查询并且不经常改变的数据Mybatis缓存MyBatis 内置了一个强大的事务性查询缓存机制,它可以非常方便地配置和定制。默认情况下,只启用了本地的会话缓存,它仅

    2022年8月8日
    0
  • 现在90,00后经常上哪些网站?喜欢看啥网站?

    现在90,00后经常上哪些网站?喜欢看啥网站?现在90,00后经常上哪些网站?喜欢看啥网站?13页PPT:揭秘90后最全研究报告!|网站运营http://www.iyunying.org/seo/sjfx/61716.html90后男生明显比90后女生更愿意在天猫上购买服装和鞋。在天猫上,男装的购买偏好为49%,女装为35%;男鞋的购物偏好为40%,女鞋为31%。90后最渴望的事情是旅行,其中旅行愿望最为迫切的是工作中的90后,达50…

    2022年7月25日
    6
  • creo每次都要配置config_config配置中心

    creo每次都要配置config_config配置中心前言每个测试用例都应该有config部分,可以配置用例级别。比如name、base_url、variables、verify、export等等案例演示fromhttprunnerimport

    2022年7月31日
    2
  • pycharm 修改镜像源_如何设置linux服务器镜像源

    pycharm 修改镜像源_如何设置linux服务器镜像源由于国外的镜像源安装Python速度较慢,选择国内的镜像速度较快,这篇文章如要讲述如何设置国内镜像源。常用镜像源:清华:https://pypi.tuna.tsinghua.edu.cn/simple阿里云:http://mirrors.aliyun.com/pypi/simple/中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/方法一:…

    2022年8月29日
    3
  • linux tty 软件包,linux学习之安装ttylinux(世界最小的linux操作系统)(转载)

    linux tty 软件包,linux学习之安装ttylinux(世界最小的linux操作系统)(转载)第一步,用WinRAR解压缩bootcd-i486-8.1.iso.gz,变成,bootcd-i486-8.1.iso镜像文件备用。第二步,在VirtualBox中新建一个虚拟电脑,并指定内存大小和硬盘大小,我们可以设定为内存256M,硬盘512M。第三步,指定虚拟光驱为bootcd-i486-8.1.iso镜像文件,双击新建的虚拟电脑图标启动即可。第四步,用虚拟光驱启动后,进入系统:输入用户名…

    2022年8月12日
    4
  • pymssql for linux[通俗易懂]

    pymssql for linux[通俗易懂]linux连接SQLServer,pymssql安装包下载,链接:https://pan.baidu.com/s/1zXyhvatpoaFRpcptmv0reA密码:y3w1安装如下:yuminstallpython-devel-ytarzxfpytz-2018.4.tar.gzcdpytz-2018.4pythonsetup.pyinstallcdta…

    2022年6月19日
    23

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号