home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / R_LA4_02.ZIP / SAVEIMAG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-20  |  2.0 KB  |  61 lines

  1. /* SAVEIMAG.C - From page 582 of "Microsoft C Programming for   */
  2. /* the IBM" by Robert Lafore. Writes a screen image to a file.  */
  3. /* Usage:   A>saveimag filename.ext   where filename.ext is     */
  4. /* the file of the screen image you want to create. This pro-   */
  5. /* gram doesn't work exactly right. It skips the first line of  */
  6. /* the screen and puts in the command line that is used to      */
  7. /* invoke this program in the file. The screen is moved up one  */
  8. /* line when this program is invoked and that's whats on the    */
  9. /* screen when this program takes over, not the exact original  */
  10. /* screen. I'm unable to figure out how to fix it. Try your     */
  11. /* luck.                                                        */
  12. /****************************************************************/
  13.  
  14. #include <stdio.h>
  15. #define SPACE '\x20'
  16.  
  17. main(argc, argv)
  18. int argc;
  19. char *argv[];
  20. {
  21. FILE *fptr;
  22. int col, row, lastchar, whatchar();
  23. char ch, buff[80];               /*buffer to hold one row*/
  24.  
  25.    if (argc != 2)  {
  26.       printf("\nType \"saveimag filename\".");
  27.       exit();
  28.    }
  29.    if((fptr = fopen(argv[1], "w")) == NULL)  {
  30.       printf("\nCan't open file %s.", argv[1]);
  31.       exit();
  32.    }
  33.    for(row = 1; row < 25; row++)  {
  34.       lastchar = 0;              /*last nonspace char*/
  35.       for(col = 1; col < 80; col++)  {
  36.          ch = whatchar(col, row);
  37.          buff[col - 1] = ch;
  38.          if(ch != SPACE)         /*remember col # of last*/
  39.             lastchar = col;      /* nonspace character*/
  40.       }
  41.       buff[++lastchar - 1] = '\n';     /*insert \n and \0 after*/
  42.       buff[++lastchar - 1] = '\0';     /*last nonspace char    */
  43.       fputs(buff, fptr);               /*write row to file*/
  44.    }
  45.    fclose(fptr);
  46. }
  47.  
  48. /* wharchar() */  /* returns char at screen location col, row */
  49.                   /* cols from 1 to 80, rows from 1 to 25 */
  50. int whatchar(col, row)
  51. int col, row;
  52. {
  53. int far *farptr;
  54. char ch;
  55.  
  56.    farptr = (int far *) 0xB0000000;
  57.    ch = *(farptr + (row - 1)*80 + col - 1);
  58.    return(ch);
  59. }
  60.  
  61.