Thread: Equivilant to BASICS Instr function (a string inside a string)

  1. #1
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428

    Equivilant to BASICS Instr function (a string inside a string)

    Im wondering what the equivilant to BASIC instr function is. what it does is takes 2 parameters (string 1, string 2) then returns true if the text from string 2 is also in string 1 (or vice-versa, im not positive) then it returns false if theyre not. Im wondering what the equivilant to this in C++ is, its about the only thing keeping me from finishing my project. ive tried strcmpi, but i cant get it to tell if one string is 'inside' the other. thanks for any help!

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    you could use:
    Code:
    char *strstr( const char *string, const char *strCharSet );
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    thanks, but i still cant get it to work...heres some code:


    char *instr;
    ...
    instr=strstr(question[i],say);
    if(instr!=NULL)
    ...
    ...

    now even if say is in question[i] and vice-versa (it loops through all of the questions) it still wont continue, it will just skip the whole if statement. any ideas?

  4. #4
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    AH! stupid mistake on my part. Uraldor, that did work, just forgot to initialize a variable! thanks!

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    no problem.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM