C program to send 3 lines of text (to a printer)

109 Views Asked by At

I need to code a program that takes input from a given register (sending bytes) to a printer and the first sentence has to be the student name in uppercase which I tried with toupper() by converting the register to a given variable (char ch;), though the given result was not met.

The next one is for the faculty number (it says in "condensed" font? Not sure what that is supposed to mean, please correct me if I'm wrong but I take it as it's supposed to be all lowercase?)

Finally, the last given sentence should print the date on the screen as well but unfortunately it doesn't say whether it should take the system date or whatever. (I've done it using printf and written the current date)

Here is the code I've written so far: (the toupper() function does not work)

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <bios.h>
#include <string.h>
#include <ctype.h>
void main()
{
  int i; char ch; char row[1000];
  union REGS r; 
  clrscr();
   memset(row,0,sizeof(row));
   r.h.ah=0; // function 0h
   int86(0x16,&r,&r);
  for(i=0; i<1;i++)
  {
     ch = row[i];
     printf("student name", toupper(ch));
     ch = r.h.al;
     r.h.ah=0;
     int86(0x17,&r,&r);
     r.x.dx=0;
     printf("\n");
     printf("16630960",row[i]);
     row[i]=r.h.al;
     r.h.ah=0;
     int86(0x17,&r,&r);
     r.x.dx=0;
     printf("\n");
     printf("10-04-2022",row[i]);
     row[i]=r.h.al;
     r.h.ah=0;
     int86(0x17,&r,&r);
     r.x.dx=0;
 }
 r.h.ah=0;
 r.h.al=0x0A;
 r.x.dx=0;
 int86(0x17,&r,&r);
 getch();
 delay(100);
}
1

There are 1 best solutions below

2
On

I am not sure what all that DOS interrupt thing is doing but I can at least fix the 'uppercase is broken' complaint

printf("student name", toupper(ch));

You are attempting to print one character of the name (thats probably not correct, but lets at least get that one character printed)

printf("student name %c", toupper(ch));

Now you need to fix all the other printfs

to convert whole string to upper case, assuming 'row' contains the string

 int len = strlen(row);
 for(int i = 0; i < len; i++){
     row[i] = toupper(row[i]);
 }