Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to find a word in a string in C

1 Answer

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

int main(void)
{
    char sentence[50] = "Linux c programming";
    char word[20] = "Linux";

    if (strstr(sentence, word) != NULL)
        printf("Found\n"); // Found
    else
        printf("NOT Found\n");
    
    if (strstr(sentence, "linux") != NULL)
        printf("Found\n"); 
    else
        printf("NOT Found\n"); // NOT Found
   
    // find also a part of the word
    if (strstr(sentence, "Lin") != NULL)
        printf("Found\n"); // Found
    else
        printf("NOT Found\n"); 
    
    return 0;
}


/*
run:

Found
NOT Found
Found

*/


answered Oct 25, 2014 by avibootz
edited Nov 8, 2025 by avibootz

Related questions

1 answer 55 views
1 answer 64 views
1 answer 124 views
1 answer 92 views
1 answer 126 views
...