User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:strstr

strstr

#include <stdlib.h>
char *strstr(const char *str1, const char *str2);

strstr C Sourcecode Example

/* 
 * strstr example code
 * http://code-reference.com/c/string.h/strstr
 */
#include <stdio.h>
#include <string.h>
 
int main ( void )
{
   char str[] = "42 is the result or ? but what was the question";
   char *ptr;
   // set the Pointer ptr to "or ?"
   ptr = strstr (str, "or ?");
   // replace the text with "yes"
   strncpy (ptr, "yes", 3);
   printf("%s\n",str);
   return 0;
}

output of strstr c example

  42 is the result yes? but what was the question
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/string.h/strstr.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz