Thread: File I/o

  1. #1
    Registered User
    Join Date
    Mar 2005

    File I/o

    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:

    /* 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*/
    		/*found newline character that ends line*/
    				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;
    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<<"I am doing fine";
    return 0;
    Last edited by Salem; 03-19-2005 at 01:55 AM. Reason: unbolden the code tags

  2. #2
    Spaced Cadet
    Join Date
    Aug 2003
     cout.sync_with_stdio(true); //Sync cout with the C io functions
    freopen("file.txt", "w", stdout); //stdin for cin
    Put that before you use cout.
    You'll need <cstdio> (maybe <cstdlib>)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 05:56 AM