help in c code

Discussion in 'QnA (read only)' started by cyboincomp, Mar 15, 2006.

Thread Status:
Not open for further replies.
  1. cyboincomp

    cyboincomp New Member

    Joined:
    Feb 24, 2005
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    mumbai
    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.
     
  2. Desmond David

    Desmond David Destroy Erase Improve

    Joined:
    Apr 9, 2005
    Messages:
    5,779
    Likes Received:
    80
    Trophy Points:
    48
    Location:
    Pune
    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!!
     
  3. hafees

    hafees New Member

    Joined:
    Feb 25, 2004
    Messages:
    405
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Kerala
    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
     
  4. shakti

    shakti New Member

    Joined:
    Jun 16, 2005
    Messages:
    120
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    visnagar
    It May Work for u .
    Any Way Best of Luck.
     
  5. sakumar79

    sakumar79 Active Member

    Joined:
    Nov 28, 2004
    Messages:
    2,441
    Likes Received:
    9
    Trophy Points:
    38
    Location:
    Madurai
    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
     
  6. tuxfan

    tuxfan New Member

    Joined:
    Feb 4, 2004
    Messages:
    2,653
    Likes Received:
    9
    Trophy Points:
    0
    Location:
    Mumbai
    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.
     
  7. ilugd

    ilugd Beware of the innocent

    Joined:
    Dec 25, 2005
    Messages:
    1,009
    Likes Received:
    3
    Trophy Points:
    0
    What about win32 api

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

    aadipa New Member

    Joined:
    Feb 12, 2004
    Messages:
    997
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    Palghar, Mumbai
    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.
     
  9. vinaypatel

    vinaypatel New Member

    Joined:
    Oct 30, 2004
    Messages:
    227
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Visnagar

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

    enjoy
     
  10. vinaypatel

    vinaypatel New Member

    Joined:
    Oct 30, 2004
    Messages:
    227
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Visnagar
    @shakti

    not it may but it should use BIOSPRINT
     
Thread Status:
Not open for further replies.

Share This Page