#include #include #include #include #include char GetAnswer(char *OK) {char Choice; do Choice=toupper(getch()); while (!strchr(OK,Choice)); return(Choice); } void OutputDirection(ofstream &Dest) {char FileName[40]; int Done; do { Done=1; // Assume ok. Will be ok unless a device open fails cout << "Output Destination:\nS)creen P)rinter D)isk\n"; cout.flush(); switch (GetAnswer("SPD")) { case 'S': Dest.open("con"); if (Dest.fail()) { cout << "Attempt to Attach to Screen Failed\n"; Done=0; Dest.close(); } break; case 'P': Dest.open("prn"); if (Dest.fail()) { cout << "Attempt to Attach to Printer Failed...Is Printer On Line?\n"; Done=0; Dest.close(); } break; case 'D': cin.ignore(); cout << "Enter Filename to Open >"; cin >> FileName; Dest.open(FileName,ios::out); if (Dest.fail()) { cout << "Attempt to Open " << FileName << " Failed\n"; Done=0; Dest.close(); } } } while (!Done); } // Open a file for reading. If file not opened, return -1, else return 0 int OpenForRead(ifstream &Source) {char Filename[40]; cout << "Enter File to Open >"; cin >> Filename; Source.open(Filename,ios::in|ios::nocreate); if (Source.fail()) return(-1); return(0); } // Input a string from a stream, terminating when \n // is encountered. The terminator \n is discarded. void fgetline(ifstream &Incoming,char Str[]) {int i=0; char Dummy; do { Incoming.get(Str[i]); i++; } while (Str[i-1] != '\n' && !Incoming.eof()); Str[i-1]='\0'; }