Thread: Program Stops Responding.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    14

    Program Stops Responding.

    I'm having a problem with my program deciding to stop responding. The program is as follows:

    Code:
    #include <iostream.h>
    main()
    {
        char * q = new char [100];
        char * i = new char [30];
        char * a = new char [30];
        q = new char [100]; i = new char [30]; a = new char [30];
        q = "What is 2 + 2?\n";
        cout << q;
        cin >> i;
        a = "4";
        if (i == a)
            cout << "Correct.\n";
        else
            cout << "No, answer is " << a << ".\n";
        delete q; delete i; delete a;
    }

    The program has a simple purpose: the goal is to have it be a sort of study guide. It will also be the first program I use new or delete in.

    I had a similar problem awhile back when I learned the basics of normal C. I would forget the ampersand before my inputs in scanf and it would stop responding in the exact same way, but I didn't use scanf here.

    I'm not certain, ut I think it's a similar problem with using new. Removing the delete command didn't fix it.

    If it matters, I use the Digital Mars compiler, which is run from the command line, cmd.

    EDIT: I have made a small modification so that the first 3 lines no longer make it so that memory for the strings is allocated twice, it now says this:
    [CODE]char * q; char * i; char * a;[CODE]
    Also, I thought it might help to mention that I don't get any errors or warnings. I don't see a problem, but there clearly is one. I don't tthink my program would just quit responding like that.
    Last edited by KittenAqua; 12-15-2011 at 07:29 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program suddenly stops working.
    By KittenAqua in forum C Programming
    Replies: 5
    Last Post: 10-18-2011, 05:45 AM
  2. MessageBox stops program flow
    By Ducky in forum Windows Programming
    Replies: 3
    Last Post: 06-20-2011, 10:40 PM
  3. Program stops working as soon as I input value?..
    By darkmagic in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2011, 02:18 AM
  4. program stops before EOF
    By doia in forum C Programming
    Replies: 2
    Last Post: 03-22-2010, 12:10 PM
  5. Program stops executing
    By bargomer in forum C++ Programming
    Replies: 16
    Last Post: 04-26-2008, 12:05 PM