strstr example

This is a discussion on strstr example within the C++ Programming forums, part of the General Programming Boards category; Can someone show me an example of strstr and/or strcasestr please? I'd like to use it to check for a ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question strstr example

    Can someone show me an example of strstr and/or strcasestr please? I'd like to use it to check for a certain number of letters after the specified number.

    Code:
    example:
    1 This would be the text I'm searching for
    2 not this
    3 not this

  2. #2
    someguy
    Guest
    strstr(str1,str2) will return the index of the first occurance of str1 in str2, so if you wanted everything up to number 2 as in your example,

    strstr(myCstring,2) will return the index of the number 2 in your string, thus you would take everything from 0 to the returned index - 1

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    In my program I'm using integers as the sign things, that won't work. Is there another function that uses numbers in the sameway this function uses letters?

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    do u want to find text after 1. and before 2.?

  5. #5
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Yes, but the numbers change. So at one time it might be 1 and another it might be 3. So, I used an interval. How would I do that?

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    well how do u want the user to search
    will he have any alternatives like the nr
    or is he going to search for a string or character?

  7. #7
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    The user inputs text, the program checks every string after a certain number; checking for a match. Then the same integer is used on an output file. That string is taken and then printed onto the screen. I already have the basic program but I need a function for using integer variables as the signs.

  8. #8
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953

    Just an idea!

    You can make your own function and use it to search for a letter or a number in a file...
    You characters in the file to a string and then, make a pointer to check each character...
    Of you can do the checking using the get pointer of the file stream you are using...
    none...

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, 08:53 AM
  2. Quick Ques on String Manipulation
    By ckuttruff in forum C Programming
    Replies: 8
    Last Post: 06-22-2008, 10: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, 07:42 AM
  5. Question about strstr()
    By choykawairicky in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2004, 08:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21