How to use strstr() function to find the first occurrence of substring in string with C

1 Answer

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

int main() {
    const char s[] = "c java c++ java php c";
    const char needle[] = "java";
    
    char *p = strstr(s, needle);

    printf("%s\n", p); 
    
    printf("%p\n", s); 
    printf("%p\n", p); 

    return 0;
}
         
        
        
         
/*
run:

java c++ java php c
0x7fff42e396e0
0x7fff42e396e2
     
*/

 



answered Jan 19, 2021 by avibootz
...