C语言strstr

strstr函数用于在字符串中查找指定子串的首次出现。它返回子串在原字符串中的指针,若未找到则返回NULL。不包括终止的空字符。
摘要由CSDN通过智能技术生成

char *strstr( const char *string, const char *strCharSet );

Libraries

LIBC.LIBSingle thread static library, retail version
  


Return Value

Each of these functions returns a pointer to the first occurrence of strCharSet in string, or NULL if strCharSet does not appear in string. If strCharSet points to a string of zero length, the function returns string.

Parameters

string

Null-terminated string to search

strCharSet

Null-terminated string to search for

Remarks

The strstr function returns a pointer to the first occurrence of strCharSet in string. The search does not include terminating null characters. wcsstr and _mbsstr are wide-character and multibyte-character versions of strstr. The arguments and return value of wcsstr are wide-character strings; those of _mbsstr are multibyte-character strings. These three functions behave identically otherwise.

e.g:

#include "stdafx.h"
#include "string.h"

int main(int argc, char* argv[])
{
	char *str = "hello python,hello word.";
    char *s = "llo";
    char *p;
    p = strstr(str,s);
    if(p)
	{
        printf("%s",p);
		printf("\r\n");
	}
    else
	{
        printf("strstr had not found %s!",s);
	}
    getchar();
	return 0;
}


#include "stdafx.h"
#include "string.h"

int main(int argc, char* argv[])
{
	char *str = "hello python,hello word.";
    char *s = "c++";
    char *p;
    p = strstr(str,s);
    if(p)
	{
        printf("%s",p);
		printf("\r\n");
	}
    else
	{
        printf("strstr had not found %s!",s);
	}
    getchar();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值