Dear Friends,
I have written the code below in an effort of laerning File I/O and port programming. I am coding using the VC++ 6.0 compiler. The code runs well. Pliz someone help me modify the code so that the program output is captured and saved to a file. The program is to prompt a user for a filename.
My code is:
Code:
/* program to read and write to and from the printer port.*/
/* the three port registers are used*/
#include <iostream>
#include <string>
#include <time.h>
#include <conio.h>
#define DATA 0x378 /*Data Register base address*/
#define STATUS DATA+1 /* Status Register address*/
#define CONTROL DATA+2 /*Control Register address*/
using namespace std;
int main()
{
//prepare for processing text
bool MoreLinesToProcess=true;
while (MoreLinesToProcess){
//process next line
bool MoreCharactersOnCurrentLine=true;
cout<<"please type a line of text:"<<endl;
while (MoreCharactersOnCurrentLine){
/*process next character on current line*/
char s,n; //CurrentCharacter;
if (cin.get(s)){
/*process current character on current line*/
if(s=='\n')
/*found newline character that ends line*/
MoreCharactersOnCurrentLine=false;
else {
_outp(CONTROL,_inp(CONTROL)&0xF0|0x04); /*initialise the CONTROL port for data input*/
_outp(DATA, s); /*write c to the DATA register*/
clock_t start_time;
start_time=clock();
while ((clock()-start_time)<0.25*CLK_TCK);/*propagation delay time*/
n=(_inp(STATUS)&0xF0); /* read MSnibble*/
n=n|(_inp(CONTROL)&0x0F);/*Read LSnibble*/
n=n^0x84; /*toggle bit 2 and 7 */STROBE pin is hardware inverted.*/
cout<<n;
}
}
}
}
cout<<"I am doing fine";
return 0;
}