0

I'm studing now and I got this homework / tasks to do:

1) If you press the CTRL + L key, all numeric symbols should change the color.

2) If you press the CTRL + S key, you will get the length of the word, left from the cursor.

I found this function int bioskey(int cmd); So now I can check if the key is pressed, but how to change the color only of numeric symbols, or read words from console to get their length ?

Spektre
  • 41,942
  • 8
  • 91
  • 312
  • 4
    Good question. Been about 20 years since I used Turbo C++. – user4581301 Nov 07 '16 at 19:32
  • Get a modern compiler. – Jesper Juhl Nov 07 '16 at 19:33
  • 1
    You do it in a similar way as you would for Object Pascal, Perl, or B. Seriously, *get a more up to date compiler*. – Bathsheba Nov 07 '16 at 19:38
  • The POINT is to make this project for DOS – Oles Pankiv Nov 07 '16 at 19:59
  • I don't use an old compiler in real application, but our teachers are some times strange peoplse – Oles Pankiv Nov 07 '16 at 20:00
  • 1
    And now you learn things that we have already forgotten, because nobody does that anymore. Too bad. – Bo Persson Nov 07 '16 at 20:11
  • Well, not my fault :( – Oles Pankiv Nov 07 '16 at 21:41
  • But looks like i should delete this question – Oles Pankiv Nov 07 '16 at 21:42
  • Added answer. From my point of view it is a valid question (even if title may be a bit misleading). If you are bound to some IDE/compiler/platform then comments to use something else are not really helpful and sound more like excuses how something not to get done instead of helping. I know TC++ is "really" outdated but that is irrelevant in this case. Anyway newest does not mean better and usually only leads to more unnecessarily work later (appart from some exceptions) and lead us to the state of the Art mess we are now in SW world... – Spektre Nov 08 '16 at 10:06

1 Answers1

1

Some of us still remember the MS-DOS (let it rest in peace or pieces...)

if you are really in MS-DOS then you can not expect that the content of the console would be changed in colors for only specific areas. You need to do that your self. The problem is we do not know anything about your project background so we do not know what and how yours stuff is represented,rendered/outputed/inputed etc...

I assume EGA/VGA BIOS text mode is used so you can exploit direct access to the VRAM. So you need to set pointer to the address B800:0000 and handle it as array where each character on screen has 2 BYTEs. one is color attribute and the other is ASCII code (not sure in which order anymore)...

So for already rendered stuff you just:

  1. loop through whole screen

    usually 80x25x2 Bytes

  2. test each ASCII for alpha numeric value

    so ASCII code >= '0' and code<='9' for numbers or add all the stuff you are considering as alphanumeric like code>' ' and code<='9'.

  3. change colors for selected characters

    just by changing the attribute byte.

When you put it together for numbers it will look like this:

char far *scr=(char far*)0x0B0000000;
int x,y,a;
for (a=0,y=0;y<25;y++)
 for (x=0;x<80;x++,a+=2)
  if ((scr[a+0]>='0')&&((scr[a+0]<='9'))
  {
  scr[a+1]=7; //attribute with the different color here
  }

if it does not work than try swap scr[a+0] and scr[a+1]. If an exception occur then you are not in MS-DOS and you do not have access to VRAM. In that case use DOS-BOX or driver that allows access to memory like dllportio ... For more info see some more or less related QA's:

If you got problem with the CTRL+Key detection not sure if in-build function in TC++ allows CTRL (was too long ago) then you can exploit BIOS or even hook up the keyboard ISR. See the second link where ISR for keyboard handler is there present... You can port it to C++ or google there must be a lot of examples out there especially TP7.0 (which is pascal but easily portable to TC++)

Community
  • 1
  • 1
Spektre
  • 41,942
  • 8
  • 91
  • 312