0

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);
}
pm100
  • 48,078
  • 23
  • 82
  • 145
sens31
  • 27
  • 5
  • first, learn how to use printf, you need some '%', %d' or '%c' etc in the format string. https://man7.org/linux/man-pages/man3/printf.3.html – pm100 Apr 10 '22 at 17:14
  • You urgently need a good C beginner's book of the presence. The last time I saw usage of such old API was in the last millennium. Use the internet to look up the documentation of functions, if your current environment does not provide it. – the busybee Apr 10 '22 at 17:25
  • @thebusybee Well you're not far from the truth. The things we study are practically from the last millennium, we weren't really given a proper explanation of how registers work and all that, they just said "you've studied c++ so you gotta know it". – sens31 Apr 10 '22 at 17:28
  • Well, C++ and C are quite different languages, even if C++ was derived from C, many years ago. So it is not true that C++ experience helps with C. -- Anyway, _why at all_ do you need to use this ancient API? Do you need to program antic machines? -- Can't you simply drop this course and spend your time doing something reasonable? – the busybee Apr 10 '22 at 17:33
  • @thebusybee It's a mandatory subject, believe it or not. If I could drop it, I would in an instant. – sens31 Apr 10 '22 at 17:35

1 Answers1

0

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]);
 }
pm100
  • 48,078
  • 23
  • 82
  • 145
  • Basically it's supposed to convert the given string (rather the given chars) to a full uppercase one. I fixed it as you have given but it doesn't convert it, unfortunately. – sens31 Apr 10 '22 at 17:25
  • @sens31 - yes well you only call it with one character. Loop over all the characters in the string. See edit of my answer – pm100 Apr 10 '22 at 17:41