Thread: floppy eraser error catching!

  1. #1
    C++ beginner
    Join Date
    Jun 2004
    Posts
    66

    floppy eraser error catching!

    I have a program that erases junk on a floppy disc that is inserted in a drive...

    I want to implement a try - catch statement that 'tries' to delete the things on the floppy.. but 'catches' the program if a) there is no floppy in the drive.... or b) there are no fdiles on the floppy....

    I have tried numerous websites but they are all hard to follow.. or are tough to relate to my program.. so I was wondering if someone could code one into the code that I already have? so I can learn how it works?

    HEre is the code I am working with...

    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    
    void getInput();
    void erase();
    
    int main()
     {
     getInput();
     //calls the get input function.
     
     }
     
     
    
     
    void getInput()
    {
      int choice, choice2;
         system("cls"); //clears the screen...just to keep it clean.
         cout << "This program will clean your floppy of files. 1=continue 2=quit" << endl;
         cin >> choice;
         
           if (choice == 1)
            {
             
               erase();
               
             }
           
           else
            {
                cout << "Thank you for playing! Goodbye!" << endl;
                system("pause");
                return  ;
            }       
         
      }
    //end of get input
    
    void erase()
      {
         int choice2;
           system("del A:\\");
           cout << " " << endl;
           cout << " Do you have more to erase? 1=yes 2=no" <<endl;
           cin >> choice2;
             
              if(choice2 == 1)
                {
                  getInput();
                   // this if statement calls the get input function...whice takes it
                   // back to the beginning.
                }
               
              else
                {
                 cout <<" Thank you for using my program! " << endl;
                 system("pause");
                 return  ;
                }
       }
    //end of erase

    Inside the erase function...the line with: system("del a:\\"); is where I want the statement to be at...


    If I were shown how to impliment something like this.. I would much apprechiate it.
    Oh my goodness.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    the problem is you can't retrieve the result from the command processor in order to detect an error if it occurs.
    Last edited by Sebastiani; 01-22-2005 at 10:04 PM.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    C++ beginner
    Join Date
    Jun 2004
    Posts
    66
    that's the thing...

    I need to check before I call the system... but I don't know how to go about checking...
    Oh my goodness.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    you can't. but if you wrote a batch file to do most of the dirty work you could probably pipe the result to a file and then have the program get the result from there.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    C++ beginner
    Join Date
    Jun 2004
    Posts
    66
    That sounds like that is more trouble than it's worth.. there has to be a way to check...
    Oh my goodness.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Quote Originally Posted by mabufo
    there has to be a way to check...
    Quote Originally Posted by Sebastiani
    you can't
    If you're going to make system calls the only way to check is to pipe the output elsewhere. This can of course be done as part of the system call
    Code:
    system("program > file.txt");
    There was a thread a few days ago that discussed how to solve some problems associated with this, including getting rid of any "Are you sure?" messages.

    Keep in mind that your program is highly OS-dependant and won't work if the user has changed any default directories on their system, or if those programs have been deleted for any reason.

  7. #7
    Registered User Kybo_Ren's Avatar
    Join Date
    Sep 2004
    Posts
    136
    As Bugdude said, use SHFormatDrive.

    http://www.cpp-home.com/forum/viewtopic.php?t=8784

  8. #8
    C++ beginner
    Join Date
    Jun 2004
    Posts
    66
    Whatever... forget it.
    Oh my goodness.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. formatting a floppy in C
    By McMullet in forum C Programming
    Replies: 2
    Last Post: 10-10-2004, 05:20 AM
  2. making a proper image for floppy
    By EvBladeRunnervE in forum Tech Board
    Replies: 4
    Last Post: 07-31-2004, 11:27 PM
  3. floppy disk filesystems
    By Leeman_s in forum Tech Board
    Replies: 5
    Last Post: 12-10-2003, 04:54 PM
  4. testing on writing to floppy
    By Mullah in forum Windows Programming
    Replies: 5
    Last Post: 07-08-2003, 07:27 AM
  5. selecting input from a floppy
    By neilman88 in forum C++ Programming
    Replies: 1
    Last Post: 04-17-2003, 02:26 PM