strstr - C string.h

C examples for string.h:strstr

Type

function

From

<cstring> 
<string.h>

Description

Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.

Prototype

const char * strstr ( const char * str1, const char * str2 );
      char * strstr (       char * str1, const char * str2 );

Parameters

Parameter Description
str1 C string to be scanned.
str2 C string containing the sequence of characters to match.

Return Value

A pointer to the first occurrence in str1 of the entire sequence of characters specified in str2

A null pointer if the sequence is not present in str1.

Demo Code

#include <stdio.h>
#include <string.h>

int main ()/*w w w  .  j a v a 2  s. c  o  m*/
{
  char str[] ="This is a simple string";
  char * pch;
  pch = strstr (str,"simple");
  strncpy (pch,"sample",6);
  puts (str);
  return 0;
}

Related Tutorials