need to input whats on screen to file?? 
Author Message
 need to input whats on screen to file??

Hello please help this newbie with what is probably a simple
question but has me at a standstill. I need to run the program
and dump what is on the screen to a file. I just can't seem to
see how i can do this. Any help would be most appreciated
Matt

/* program to create workload distribution */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop
#define MAXPATH 64
#define MAXLINE 256
#define WIND 3
#define FIRE 4
#define LIABILITY 3
#define EXPLOSION 4
#define FREEZING 3
#define LIGHTENING 2
#define SMOKE 4
#define THEFT_ON 1
#define THEFT_OFF 1
#define VAND_MM 3
#define VEHICLES 3
#define WATER 3
#define OTHER 3
main(void)
{
        char ch;
        FILE *fp;
        char pathname[MAXPATH];
        char line[MAXLINE];
        long int claim; /* claim number */
        int peril; /* peril code */
        int type;

                printf("dispatch name: ");/*gets employee work file */
        gets(pathname);
        if (*pathname == '\0')
                return (0);

                fp = fopen(pathname, "a+"); /*add work or start new file*/

        printf("claim:");

        scanf("%d" ,&claim);

        printf("peril:");

        scanf("%d" ,&peril);

 if (peril == 29)
          {
                 printf("severity :%d" ,WIND);
                 printf("\n\n");

                 printf("choose one of the following and press ENTER:\n\n");
                 printf("damage to roof only -----------------------------type 1.\n");
                 printf("damage to roof and interior,contents,carpet------type 2.\n");
                 printf("major damage ,tornado large loss-----------------type 3.\n\n");

                 scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",WIND);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(WIND + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(WIND + 4));
                  }
                }
 if (peril == 5)
                {
                  printf("severity : %d " , FIRE);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("minor fire damage, small loss--------------------type 1.\n");
                  printf("kitchen fire , smoke damage, mediun size loss----type 2.\n");
                  printf("large fire , major structure damage--------------type 3.\n");
                  printf("total loss---------------------------------------type 4.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",FIRE);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(FIRE + 2));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(FIRE + 6));
                  }
                  if (type == 4)
                  {
                  printf("total value work load:%d",(FIRE + 10));
        }
                }
 if (peril == 2)
                {
                  printf("severity : %d " , LIABILITY);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("inspect only for photos--------------------------type 1.\n");
                  printf("minor damages to be estimated--------------------type 2.\n");
                  printf("large loss , statements etc----------------------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",LIABILITY);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(LIABILITY + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(LIABILITY + 3));
                  }
                }
 if (peril == 4)
                {
                  printf("severity : %d " , EXPLOSION);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("cosmetic damage from nearby explosion------------type 1.\n");
                  printf("medium damage from explosion, subro work etc-----type 2.\n");
                  printf("total loss.--------------------------------------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",EXPLOSION);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(EXPLOSION + 2));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(EXPLOSION + 6));
                  }
                }
 if (peril == 7)
                {
                  printf("severity : %d " , FREEZING);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("small loss from frozen pipe----------------------type 1.\n");
                  printf("number of rooms damaged,carpets,medium loss------type 2.\n");
                  printf("large loss contents damaged----------------------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",FREEZING);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(FREEZING + 2));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(FREEZING + 4));
                  }
                }
 if (peril == 11)
                {
                  printf("severity : %d " , LIGHTENING);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("minor damage well pump,electrical svc------------type 1.\n");
                  printf("medium loss some fire damage electrical etc------type 2.\n");
                  printf("large loss.--------------------------------------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",LIGHTENING);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(LIGHTENING + 2));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(LIGHTENING + 5));
                  }
                }
 if (peril == 16)
                {
                  printf("severity : %d " , SMOKE);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("smoke limited to 1 room--------------------------type 1.\n");
                  printf("smoke damage thruout house medium size loss------type 2.\n");
                  printf("large loss, whole house clean and paint----------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",SMOKE);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(SMOKE + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(SMOKE + 3));
                  }
                }
 if (peril == 17)
                {
                  printf("severity : %d " , THEFT_ON);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("small loss few items-----------------------------type 1.\n");
                  printf("medium loss list of items------------------------type 2.\n");
                  printf("large loss limits apply many items---------------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",THEFT_ON);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(THEFT_ON + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(THEFT_ON + 3));
                  }
                }
 if (peril == 18)
                {
                  printf("severity : %d " , THEFT_OFF);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("few items stolen-- ------------------------------type 1.\n");
                  printf("large list investigation necessary---------------type 2.\n");
                  printf("possible fraud recorded statement etc------------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",THEFT_OFF);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(THEFT_OFF + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(THEFT_OFF + 3));
                  }
                }
 if (peril == 19)
                {
                  printf("severity : %d " , VAND_MM);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("minor damage by vandals broken glass ,etc--------type 1.\n");
                  printf("medium loss, house egged,spraypaint etc----------type 2.\n");
                  printf("large loss,ransacked house  damage everwhere-----type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",VAND_MM);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(VAND_MM + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(VAND_MM + 3));
                  }
                }
 if (peril == 24)
                {
                  printf("severity : %d " , VEHICLES);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("minor car hit to landscape-----------------------type 1.\n");
                  printf("damage to landscape minor house damage-----------type 2.\n");
                  printf("landscape and major damage to dwelling-----------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",VEHICLES);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(VEHICLES + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(VEHICLES + 3));
                  }
                }
 if (peril == 25)
                {
                  printf("severity : %d " , WATER);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("one room-flooring damage, ceiling----------------type 1.\n");
                  printf("number of rooms damaged emg svc was necessary----type 2.\n");
                  printf("large loss contents damaged number of rooms------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",WATER);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(WATER + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(WATER + 3));
                  }
                }
 if (peril == 30)
                {
                  printf("severity : %d " , OTHER);
                  printf("\n");

                  printf("choose one of the following and press ENTER:\n\n");
                  printf("tree hit or minor damage to dwelling-------------type 1.\n");
                  printf("damage to roof and interior ,contents,carpet-----type 2.\n");
                  printf("total loss.--------------------------------------type 3.\n\n");

                  scanf("%d" , &type);
                  if (type == 1)
                  {
                  printf("total value work load:%d",OTHER);
                  }
                  if (type == 2)
                  {
                  printf("total value work load:%d",(OTHER + 1));
                  }
                  if (type == 3)
                  {
                  printf("total value work load:%d",(OTHER + 3));
                  }
                 }
                 while ((ch = getchar()) != '\n')
                        fputc(ch, fp);
                        fputc('\n' , fp);

         fclose(fp);

        return (0);

Quote:
}



Sun, 14 Oct 2001 03:00:00 GMT  
 need to input whats on screen to file??

Quote:

>Hello please help this newbie with what is probably a simple
>question but has me at a standstill. I need to run the program
>and dump what is on the screen to a file.

Run it on a UNIX system and use the "tee" command to redirect the output to a
file and the terminal at the same time. This lets you interact with the
program, yet save a copy of its output.

Quote:
>/* program to create workload distribution */
>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>
>#include <iostream.h>

Iostream isn't part of C, it's a C++ feature. You are in the wrong
newsgroup; if you are programming in C++, go to comp.lang.c++.

Quote:
>#include <conio.h>

Conio isn't part of C or C++, it's an extension found in DOS environments.
You can ask about this in comp.os.msdos.programmer.


Sun, 14 Oct 2001 03:00:00 GMT  
 need to input whats on screen to file??

Quote:

> Hello please help this newbie with what is probably a simple
> question but has me at a standstill. I need to run the program
> and dump what is on the screen to a file. I just can't seem to
> see how i can do this. Any help would be most appreciated
> Matt

> /* program to create workload distribution */

<HUGE SNIP!>

Look into fprintf, and fopen, or if your using DOS or UNIX just put  "> filename" after you
run the program from the prompt.



Sun, 14 Oct 2001 03:00:00 GMT  
 need to input whats on screen to file??


Quote:

>> Hello please help this newbie with what is probably a simple
>> question but has me at a standstill. I need to run the program
>> and dump what is on the screen to a file. I just can't seem to
>> see how i can do this. Any help would be most appreciated
>> Matt

>> /* program to create workload distribution */

><HUGE SNIP!>

>Look into fprintf, and fopen, or if your using DOS or UNIX just put  ">
>filename" after you
>run the program from the prompt.

As a sort of follow up to the above I am somewhat perplexed as to how to
code for pipes and redirection. Since this occurs in at least UNIX and
DOS it is not too platform specific.

As an example: I have a program called *pack* that takes two command
line arguments both are null terminated strings. The first string is
composed of control characters, the second is the users' string. Each
control character removes that class of character from the string; thus
an *s* would remove the spaces; d would remove digits etc. The output is
the modified string.

The program would be called like this:

     pack sd 3 score years and ten

returning

     scoreyearsandten

Now what if I wanted to pass it a file

     pack sd myfile

or the output of another process via a pipe:

     process | pack sd

How do I code the internals of my program to cope with that, or does the
OS deal with it and I just have to make sure that the internals are
working correctly.

This is one of those things that I'm sure I am just missing a step or
two out of the method and/or reasoning.

TIA
--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bob Wightman



Mon, 15 Oct 2001 03:00:00 GMT  
 need to input whats on screen to file??

Quote:

>As a sort of follow up to the above I am somewhat perplexed as to how to
>code for pipes and redirection. Since this occurs in at least UNIX and
>DOS it is not too platform specific.
[example snipped]

>How do I code the internals of my program to cope with that, or does the
>OS deal with it and I just have to make sure that the internals are
>working correctly.

>This is one of those things that I'm sure I am just missing a step or
>two out of the method and/or reasoning.

#if (OFF_TOPIC == ONLY_SLIGHTLY)
The operating system (technically, the command interpreter/shell)
handles it.  If you specify a command line that contains redirection
characters (e.g. <,>,| ), the command shell will attach your stdin
and/or stdout to something other than the console for you.
A pipe or filter just needs to read from stdin and write to stdout.
For example, you could cook up a quick "tee" command like
this:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  FILE **pfpa;
  int i;
  int ch;

    pfpa = malloc(argc * sizeof(FILE *));
    if (NULL != pfpa){
        pfpa[0] = stdout;
        for (i = 1; i < argc; i++){
            pfpa[i] = fopen(argv[i], "w");
            if (NULL == pfpa[i]){
                fprintf(stderr,
                        "warning: could not open \"%s\" for writing.\n",
                        argv[i]
                       );
            }
        }
        while( (ch = fgetc(stdin)) != EOF){
            for (i = 0; i < argc; i++){
                if (NULL != pfpa[i])
                     fputc(ch, pfpa[i]);
            }
        }
        for (i = 1; i < argc; i++){
            pfpa[i] = fopen(argv[i], "w");
            if (NULL != pfpa[i]){
                fclose(pfpa[i]);
            }
        }

        free(pfpa);
    }
    else{
        fprintf(stderr, "not enough memory\n");
    }
  return 0;

Quote:
}

(example only, source looks okay to me but is unchecked.
Go easy on me, guys)

#endif

    -dave

--
------------------------------------------------------------------------
* Remember to remove the spam blocker when replying.
* Return address is: dstarr AT xnet DOT com
------------------------------------------------------------------------



Mon, 15 Oct 2001 03:00:00 GMT  
 need to input whats on screen to file??

Quote:

> How do I code the internals of my program to cope with that, or does the
> OS deal with it and I just have to make sure that the internals are
> working correctly.

> This is one of those things that I'm sure I am just missing a step or
> two out of the method and/or reasoning.

The OS should take care of it for you. Your programs should normally just
deal with stdin & stdout. And you can let the shell / OS deal with the
rest.


Mon, 15 Oct 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Need help with input data from file

2. Need help with input from text file

3. Only drawing whats needed using CScrollView

4. Whats teh need for delegates

5. Formating Input :: simulating 2 prompts on 1 screen

6. How to input EOF from the screen

7. Unbuffered input on VMS , screen control.

8. Copy screen input to a 2 dimensional array

9. Input screen

10. Reading Input W/o Echoing to Screen

11. Recommendations for full screen input routines?

12. enter input w/o echo to screen

 

 
Powered by phpBB® Forum Software