Thread: File I/O in Borland Turbo C++ v4.5

  1. #1
    Unregistered
    Guest

    Unhappy File I/O in Borland Turbo C++ v4.5

    writing a PC diagnostic program for my college project. No very little about coding. Problem is, the user has to be able to view error statistics of all runs of the program from a .dat or .txt file via a choice on the introductory menu of the program. I've just managed to get the dat. files to create and stay on the floppy disk but cant get them to append or be viewed. Every fresh start of the code produces blank records. The code I've used is as follows:

    void main()
    {
    file0.open("a:\\errors.dat", ios::in |ios:ut |ios::app);
    if (!file0)
    {
    cout <<"Error initialising file";
    }
    else
    {
    for (int index =4; index<4; index++)
    {
    file0 >>errors[index].error_type;
    file0 >>errors[index].no_of_faults;
    file0 <<errors[index].error_type;
    file0 <<errors[index].no_of_faults;
    }
    }

    file0.close();

    file1.open("a:\\total_errors.dat", ios::in | ios:ut |ios::app);
    if (!file1)
    {
    cout <<"Error initialising file";
    }
    else
    {
    file1 >>total_faults;
    file1 <<total_faults;
    }

    file1.close();
    menu();
    }




    in the choice function for the menu under switch I've written:



    //Switch Function
    case 3:
    file0.open("a:\\errors.txt", ios:ut |ios::app);
    if (!file0)
    {
    cout <<"Error writing to file";
    }
    else
    {
    for (int index =4; index<4; index++)
    {
    file0 <<errors[index].error_type;
    file0 <<errors[index].no_of_faults;
    }
    file0.close();
    file1.open("a:\\total_errors.txt", ios:ut |ios::app);
    if (!file1)
    {
    cout <<"Error writing to file";
    }
    else
    {
    file1 <<total_faults;
    }
    file1.close();
    exit(-1);
    }
    break;

    any help or suggestions greatly appreciated

  2. #2
    Unregistered
    Guest
    sorry...

    in the switch function it should read .dat not .txt as posted...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. File I/O problem
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 12
    Last Post: 09-03-2005, 12:14 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM