Thread: My program crashes with this code

  1. #1
    Registered User blackwyvern's Avatar
    Join Date
    Jan 2002

    Unhappy My program crashes with this code

    I am trying to it to get a user response, search it against the list of pre-defined introductions and return and introduction to the program.. but when I enter hello or any other one, the program crashes. What am I doing wrong, please.

    void introduction()
    char introarray[20][20]=
    int i;
    for (i = 0; i < 20; i++)
    int t;
    while(strstr(uresponse,introarray[t + 1])!=NULL)
    cout << "Hello, how are you?.\n";
    i = 20;

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    2 things:

    1st: instead of using strstr, use strcmp which is made for comparing strings

    2nd: uresponse is not declared inside the function, therefore, it goes out of scope if it is declared outside of the function.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Apart from what gunfinguy4 has pointed, I see that your t is not initalized to anything. Also you don't seem to increment t in the while loop either.
    The experimenter who does not know what he is looking for will not understand what he finds.
    - Claude Bernard

  4. #4
    Registered User blackwyvern's Avatar
    Join Date
    Jan 2002
    Yeah, I took out the t because I realized I could easily just use the i. I am a fairly new programmer... well, I am not new but I havent done anything in about 6 years and it is hard to remember everything, or at times anything. Thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Writing code for a program in C
    By Sure in forum C Programming
    Replies: 7
    Last Post: 06-11-2005, 01:33 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Can someone help me understand this example program
    By Guti14 in forum C Programming
    Replies: 6
    Last Post: 09-06-2004, 12:19 PM