Thread: Substrings

  1. #1
    random number generator reRanger's Avatar
    Join Date
    Oct 2004


    How can I search one input string for two substrings?

    This does not work:

    #include <stdio.h>
    #include <fstream>
    #include <iostream>
    #include <string.h>
    #include <windows.h>
    using namespace std;
    int main()
    char resp1[]="good,no"; 
    char name[256];
    char resp[]="not";//-Check*
    char name1[256];//-Check*
    cout<< "Hello, how are you today?\n"<< endl;                     
    cin.getline (name,256);
    char * pch;
    pch=strstr (name, "good"); //Searching for “good” in  ^ Char str
    if(pch !=NULL) 
    char * pch;//-Check*
    pch=strstr (name1, "not"); //Searching for “good” in  ^ Char str//-Check*
    if(pch !=NULL)
    cout<< "I am glad to hear you are doing well today.\n"<< endl;                     
    cout<< "Is anything wrong at all? Would you like to discuss it? \n"<< endl;                      
    return 0;  //END
    Last edited by reRanger; 11-28-2004 at 12:15 PM.
    "Nay! But you love the present life!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help, extracting substrings from a string
    By doubty in forum C Programming
    Replies: 1
    Last Post: 06-17-2009, 11:57 PM
  2. vector of substrings
    By manav in forum C++ Programming
    Replies: 47
    Last Post: 05-10-2008, 02:05 PM
  3. Searching for a series of possible substrings inside a string
    By andrew.bolster in forum C Programming
    Replies: 7
    Last Post: 02-10-2008, 02:20 AM
  4. substrings
    By arjunajay in forum C++ Programming
    Replies: 30
    Last Post: 06-10-2005, 09:13 PM
  5. Searching strings - substring's
    By Vber in forum C Programming
    Replies: 4
    Last Post: 02-06-2003, 12:05 PM