Thread: Strstr

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    39

    Question Strstr

    Hi

    I have a string say " I am a Novice"

    lets say i want to find if "Nov" is there in the program, then what I do is

    use strstr function which returns me a pointer to the first occurence of the string in the sentence, now i want to get the position of this first occurence element in the character array. how do i do that?

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    You could simply subtract the base address of the original string from the pointer returned by strstr . For eg. your string is char s[]="I am a Novice", then (pointer returned by strstr)-s will give you the position.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create Copies of Files
    By Kanshu in forum C++ Programming
    Replies: 13
    Last Post: 05-09-2009, 07:53 AM
  2. Quick Ques on String Manipulation
    By ckuttruff in forum C Programming
    Replies: 8
    Last Post: 06-22-2008, 09:32 PM
  3. linked list using strstr
    By ilovec.. in forum C Programming
    Replies: 3
    Last Post: 11-04-2006, 01:30 PM
  4. strstr on a wchar array
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-28-2006, 06:42 AM
  5. Question about strstr()
    By choykawairicky in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2004, 08:18 PM