1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Searching for sub-word

Discussion in 'C' started by Gravedigger, Dec 20, 2008.

  1. Gravedigger

    Gravedigger New Member

    Joined:
    Dec 20, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code: Cpp
    Code:
    #include <string.h>
    #include <stdio.h>
    
    int main()
    {
            char word[80], subword[80], *poz;
            printf("Enter wordn");
            scanf("%s",word);
            printf("Enter subwordn");
            scanf("%s",subword);
            if ((poz = strstr(word, subword)))
            {
                    printf("%s is sub word of %s at position %dn",
                                    subword,word,poz - word + 1);
            }
            else { printf("%s isn't subword of %sn",subword,word); }
            return 0;
    }
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Is this a demo program, or do you have some questions about it?
    It's not very helpful just to post code without any kind of comments.
     

Share This Page