Thread: Saving screen output to file

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    Saving screen output to file

    I am developing a program to produce estimates (Using MS Visual Studio--'black background program' -- I don't know what platform that is considered, sorry I am a newbie). Anyways, I want to be able to either:

    1). Save the ENTIRE SCREEN OUTPUT to a file (with option Y/N to save, then get the filename from the user, then save the file---- This should be done within the program)

    (OR)

    2). To print the screen (everything in the screen, not using ALT + PRINTSCRN, either).

    Either option is fine, I just need to do one to produce a hard copy!
    Does anyone have a solution to my woes? Please, please, please, please help!

    You guys rock!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Create an "output" function that takes string. Echo all input by using this function. The "output" function should basicly store a buffer of (screen_width x screen_height) characters so that you can if need be, dump the screen contents to a file.

    Use your output function in place of standard output functions.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    You're using windows, and the windows environment for a dos console may or may not allow direct video access, but it's probably not a good idea to do that anyway - so forget the 2nd option for now.

    For the first option, it would probably be easier to ask ahead of time, and write to file at the same time as you write to screen. Look up functions such as fopen, fprintf, etc..

    If you want to save only afterwards, you could either save all the output in a buffer and dump it to disk with fwrite, or use a temporary file and copy it to the new name if the user decides to save it.
    .sect signature

  4. #4
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
     FILE *fptr;
     char name[20], last[20];
    
     if ( (fptr =  fopen( "test.txt", "w" ) ) != NULL ){
        printf("Enter first name:");
        fgets( name, sizeof name, stdin );
    
        printf("Enter sur name:");
        fgets( last, sizeof last, stdin );
    
        fprintf(fptr, "Testing file...\n" );
        fprintf(fptr, "%s  %s",  name, last );
     }
     else
         perror("test.txt");
    
          system("PAUSE");
          return 0;
    }
    Is this what u are looking for??
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by datainjector
    Code:
        printf("Enter first name:");
        fgets( name, sizeof name, stdin );
    
        printf("Enter sur name:");
        fgets( last, sizeof last, stdin );
    Is this what u are looking for??
    No. It doesn't sound like it. From the original message, they want everything on the screen dumped to a file. This would include the lines "Enter first name:" and "Enter sur name:" also, not just their input.

    As I mentioned, the best way to do this is to buffer all output and write the buffer when they elect to do a screen dump.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    10
    Datainjector - thanks, sample code is always nice to have for an answer to a question. I am putting the final touches on my program. I will test your code later and let you know if it works or not. Thanks.

    Quzah, I have no idea what you mean. Like I said earlier. I am an EXTREME newbie at C programming. I wouldn't know the first thing about doing what you described, or where to start....but thanks all the same....

    Let me clarify my question and add to it...

    1). Is is possible to even do what I initially asked for regarding the entire input screen? Save file or print the whole screen?

    (and)

    2). Is there a simplistic way to tackle this problem? I have a deadline for tomorrow and I don't want to chase rainbows that don't exist.

    To the rest of you, thanks for all your input. It is nice to have web buds that care and who are willing to help.

    You guys Rock!

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) Yes.
    2) Yes.
    However, what is simple to me, may not be simple to you. I would create a "buffer', which is a section of code (an array or whatever you choose) to store the "page" of text. Then you do something like:
    Code:
    void output( char * s )
    {
        printf( "%s", s );
        buffer( s );
    }
    I'd also make a function to write the buffer to a file. You'll need to create a function to stick the string into the buffer, and keep tabs on the dirty work of buffering the text (such as what line you're on or whatever).

    In short, no, you'll probably not have an easy time of it. But post your code attempt and we'll correct and assist. I don't provide full answers to homework.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    10
    FYI - This is not homework. This is a program for a non-profit/low profit clinic. My services are voluntary (I suppose that is why they do not care about me being a newbie programmer, if I can be called one at all). The estimates are to generate a low cost/sliding scale payment for a health provider. Again, thanks all the same and I will apply what I can to my program later and get back to you all about what worked, if anything.

    All the suggestions are very helpful and appreciated. Keep on rocking the program world guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. I'm not THAT good am I?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-19-2006, 10:08 AM