Mega Code Archive

 
Categories / C / String
 

A demonstration of seeking and finding

#include <stdio.h> #include <string.h> void main() {   char str1[] = "This string contains the key.";   char str2[] = "the key";   char str3[] = "the keys";   if(strstr(str1, str2) == NULL)     printf("\nString not found.");   else     printf("\nString: %s\n was found in string: %s",str2, str1);   if(strstr(str1, str3) == NULL)     printf("\nString not found.");   else     printf("\nWe shouldn't get to here!"); }