help in c code

Status
Not open for further replies.

cyboincomp

Broken In
i made a program in c.
its something like a quiz software.i want to add a feature such that the result of the quiz taken can be send directlt to printer and/or a file.
is there any function that will allow me to do that

secondly i want to add a time based feature into it. so that the questions can b answered in stipulated time is it posssible to do that.
 

Desmond

Destroy Erase Improve
Staff member
Admin
I am not sure about the printer task. However, try this:

Run the program from the command prompt. Navigate to your programs folder. Then type:
c:\[some path]>[program name]>prn
This will take the output of the program on the printer.

As for the time based feature, you can include dos.h ,start a for loop and use the function delay(time). Replace the "time" with appropriate delay in microseconds. Then give an output to a particular part of the screen. Make sure that it always prints on the same part, or else it will print one over the another and shift the screen upwards.

Good Luck!!
 

hafees

In the zone
try the above thing for printing. But it wont work if your printer is not connected to a parallel port. That is new age printers wont work.

I didnt get your 2nd question correctly. delay(time in milli seconds) will stop the system from processing next command. Pls explain more
 

sakumar79

Technomancer
Standard C does not provide routines for sending output to printer, but you can write to files...

For time manipulation, use time.h to monitor time gone.For waiting for keypress use conio.h to monitor keypress... Then use something like while (key not pressed) {if (time exceeds loop) exit loop with answer not set}... I think this will work as long as you just have one character to wait for ie, multiple choice questions...

Arun
 

tuxfan

Technomancer
If you have patience to study code, I can send you the code of my Y2k compliant :lol: Calendar Application made in C in 1994 under DOS.

There I have a running clock at the top (that will show you how to use time) and the application waits for a key press and also prints the calendar with various formatting (bold, italics, small fonts, etc.) However, it prints only on Dot Matrix printers on LPT1. I had access to only a DM printer at that time, so thats what I made. :)

But the main thing is my function library and header files. The calendar application was basically made as a showcase of the function library that I made. :) Those functions changed the way I (and many others who used it) wrote the C programs after that. Lots of functions that I wrote were not availalbe in standard Turbo C libraries. For example,
- save screen (to a variable or a file)
- restore screen (from a variable or a file)
- clear screen (full or part - far better substitute of clrscr())
- say (at a location with formating attributes - a far better substitute of printf())
- new colour (change only the colour of characters, see thru shadows ;))
- draw box (with co-ordinates and string)

I can send you all if you are insterested.
 

ilugd

Beware of the innocent
What about win32 api

There are functions in win32apis for printing. Why don't you use those?
 

aadipa

Padawan
The getch() waits for user input so it is not useful for time based checks, also, if you are using TC, which most college students use, then, it don't have threads concepts.

So here is my suggestion,

1. Display Question, time=0
2. answered=0, timeout=0
3. while((answered | timeout) == 0) do loop
3.1. read key from buffer
3.2. check for answer if key pressed, answered = 1, break the loop
3.3. add time from last loop to time, check for timeout, in case of timeout, timeout=1, break the loop
3.4. continue the loop
4 move to next question


Okay, now some C code to read last key pressed,
Code:
#include <dos.h>

union  REGS i,o;
struct SREGS s;


/*returns scan code of the key that has been hit*/
//Up : 72 Down : 80 Left : 75 Right : 77
int getkey()
{ while(!kbhit()) delay(25);
  i.h.ah=0x00;
  int86(0x16,&i,&o);
  return(o.h.ah);
  // ah : scan code
  }

/*returns ascii code of the key that has been hit*/
int xgetkey()
{ while(!kbhit()) delay(25);
  i.h.ah=0x00;
  int86(0x16,&i,&o);
  return(o.h.al);
  // al : ascii code
  }

unsigned char getShiftStatus() {
   i.h.ah=0x02;
   int86(0x16,&i,&o);
   return(o.h.al);
   // Bit No : Status
   // 0      : Right shift depressed
   // 1      : Left shift depressed
   // 2      : Ctrl depressed
   // 3      : Alt depressed
   // 4      : Scroll lock on
   // 5      : Num lock on
   // 6      : Caps lock on
   // 7      : Insert on
   }

For time calcs
Code:
// example from difftime() in TC
first = time(NULL);  /* Gets system
                        time */
delay(2000);         /* Waits 2 secs */
second = time(NULL); /* Gets system time
                        again */

printf("The difference is: %f seconds\n",difftime(second,first));

Hope this helps you.
 

vinaypatel

Journeyman
sakumar79 said:
Standard C does not provide routines for sending output to printer, but you can write to files...

For time manipulation, use time.h to monitor time gone.For waiting for keypress use conio.h to monitor keypress... Then use something like while (key not pressed) {if (time exceeds loop) exit loop with answer not set}... I think this will work as long as you just have one character to wait for ie, multiple choice questions...

Arun


hey man check out biosprint function it works and it is use internal interrupt routine of ur bios

enjoy
 
Status
Not open for further replies.
Top Bottom