How to find first occurrence of a word in a string using C

1 Answer

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

int main() {
    char s[50] = "c python c++ java c++ php";

    printf("%s\n", strstr(s, "c++"));
    printf("index = %i\n", strstr(s, "c++") - s);

}


 
/*
run:
 
c++ java c++ php
index = 9

*/

 



answered Apr 2, 2019 by avibootz

Related questions

...