Thread: abnormal program termination

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    9

    abnormal program termination

    Can someone look at my code and give me any idea why I'm getting abnormal program termination after the output is on the screen? It's just a simple program to open a file and then compare some letters for output. Thanx in advance.

    #include <fstream> // For file i/o
    #include <iomanip> // For cout manipulation
    #include <iostream> // For cout
    #include <stdlib.h> // For exit
    #include <string> // For elements of type char
    #include <stdio.h>

    using namespace std;

    int main ()
    {
    ifstream Code_Detail;
    ofstream Code_Out;
    string line;
    string Prefix, DocAreaCode2, Description; // Strings for Code_Detail

    Code_Detail.open ("Code_Detail.txt");
    if (Code_Detail.fail ())
    {
    cout << "Cannot Open File: " << endl;
    return EXIT_FAILURE;
    }


    Code_Out.open ("Code_Out.txt");
    if (Code_Out.fail ())
    {
    cout << "Cannot Create File: " << endl;
    return EXIT_FAILURE;
    }

    while (Code_Detail.good ())
    {
    getline(Code_Detail, line);
    Prefix=line.substr(0,2);
    DocAreaCode2=line.substr(2,2);
    Description=line.substr(4,11);

    if ((Prefix == "AA") && (Description == "MC"))
    {
    cout << Prefix << DocAreaCode2 << Description << endl;
    Code_Out << Prefix << DocAreaCode2 << Description << endl;

    }

    }

    Code_Detail.close ();
    Code_Out.close ();


    return EXIT_SUCCESS;
    }

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    first of all if you #include the "fstream" then you don't need the "iostream" b/c "fstream" has "iostream" included within itself...
    second of all you don't need to explicitly close the files b/c your next step IN THIS PROGRAM is termination and files are closed implicitly...

    when i compiled your code...everything was relatively O.K. as long as those files existed...if for example the one or reading did not exist then the program generated Exit_Failure as you designated.... HINT: it might help in the future if you would terminate the programs execution so drasticly...maybe you could just put a "cout" statment without exiting the program....

    Hint: in "stdlib.h" ..... system("pause"); ............. pauses the programs execution and asks the user to press any key on the keyboard.............. that might help you in debugging....

    hope this helped...

    Regards,
    matheo917

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    9
    Thanks, I ended up moving my getline before and after the loop. It works good now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 06-23-2006, 07:03 PM
  2. Abnormal program termination
    By Kayoss in forum C++ Programming
    Replies: 3
    Last Post: 05-16-2006, 03:29 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. quick termination of program
    By jobolikescake in forum C Programming
    Replies: 7
    Last Post: 01-20-2002, 10:59 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM