Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 15-03-2006, 02:48 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Feb 2005
Location: mumbai
Posts: 48
Default help in c code


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.
cyboincomp is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 16-03-2006, 06:07 PM   #2 (permalink)
Level 96 Headbanger
 
DeSmOnD dAvId's Avatar
 
Join Date: Apr 2005
Location: Metalopolis
Posts: 1,122
Default

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!!
__________________
"Words meant to dwell in darkness shall never see the light of day.
Words can be broken, so can bones. Execute the mandate." :twisted:


Steam : DeathMetal
Garena : death_metal27
My Blog : The Pandemonium
(Latest Post : Where does music come from?)
Guitar gear : GB&A (acoustic), ESP LTD-M50 (New :twisted:), Roland MicroCube Amp.
DeSmOnD dAvId is online now  
Old 16-03-2006, 06:51 PM   #3 (permalink)
In The Zone
 
hafees's Avatar
 
Join Date: Feb 2004
Location: Kerala
Posts: 405
Default

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
__________________
Quitters Never Win & Winners Never Quit!
hafees is offline  
Old 17-03-2006, 02:16 AM   #4 (permalink)
Broken In
 
shakti's Avatar
 
Join Date: Jun 2005
Location: visnagar
Posts: 120
Default

It May Work for u .
Any Way Best of Luck.
__________________
Mr. Infredible
shakti is offline  
Old 17-03-2006, 07:25 AM   #5 (permalink)
Human Spambot
 
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
Default

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
sakumar79 is offline  
Old 17-03-2006, 12:48 PM   #6 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default

If you have patience to study code, I can send you the code of my Y2k compliant 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.
tuxfan is offline  
Old 17-03-2006, 01:00 PM   #7 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default What about win32 api

There are functions in win32apis for printing. Why don't you use those?
ilugd is offline  
Old 17-03-2006, 01:02 PM   #8 (permalink)
Wise Old Owl
 
aadipa's Avatar
 
Join Date: Feb 2004
Location: Palghar, Mumbai
Posts: 1,000
Default

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.
__________________
i generally prefer quality over quantity
1 aadi + 1 aadi = 1 full ;)
aadipa is offline  
Old 17-03-2006, 02:28 PM   #9 (permalink)
In The Zone
 
Join Date: Oct 2004
Location: Visnagar
Posts: 227
Default

Quote:
Originally Posted by sakumar79
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
__________________
EVERY QUESTION HAVE PERFACT ANSWER

AND NOTHING IS IMPOSSIBLE
vinaypatel is offline  
Old 17-03-2006, 02:29 PM   #10 (permalink)
In The Zone
 
Join Date: Oct 2004
Location: Visnagar
Posts: 227
Default

Quote:
Originally Posted by shakti
It May Work for u .
Any Way Best of Luck.
@shakti

not it may but it should use BIOSPRINT
__________________
EVERY QUESTION HAVE PERFACT ANSWER

AND NOTHING IS IMPOSSIBLE
vinaypatel is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 05:08 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2