User talk:Amamprayil

The string compare function is short and brief when you modify it like as follows.

int strcmp(char *str, char *s) {  while(*str != '\x0' && *str == *s && *s++ && *str++); return (*str - *s);

}

Assessing Keys of the keyboard without using _bios_keybrd function.

 * 1) define UP_ARROW 0x4800
 * 2) define DOWN_ARROW 0x5000

/* How we got the UP_ARROW as 0x4800 to be defined? In the doshelp directory in C:\ drive type help ansi.sys It will show that UP_ARROW is a combination of two characters (NULL,H) in hexadecimal it is (0,48) and in decimal it is (0,72). When you use the operator leftshit (<<), 48 << 8 gives 0x4800. Similarly we can find the corresponding values for all combination keys. The combination may lie in the range from 0 to 255. For example Ctrl-Alt-Enter key on the Numeric key pad is(0,a6) or in decimal it is (0,166). Keys above 127 can also be a combination character. 255 in the table are all 1's as binary or 8, 1's or 11111111. Therefore, we are safe when shifting to 8 bits left in an unsigned int which is 16 bit. */

unsigned key(void) {	int ch1,ch2; unsigned ch; ch1 = getch; if(ch1 == 0) {		ch2 = getch; ch = ch2; ch <<= 8; return ch; }	else {		ch1 = toupper(ch1); return ch1; } }

//

//A much better simpler way to write the key function is as follows.

unsigned key(void) {           unsigned ch = 0; ch = getch; // since an unsigned int is stored in 16 bits and an int is stored in 16 bits this is permissible. ch = toupper(ch); if(ch == 0) {                  ch = getch; ch <<= 8; }           return ch; }

// // or // unsigned int key(void) {	int ch = 0,ch1 = 0; unsigned int ch2 = 0; ch = getch; if(ch == 0) {		ch1 = getch; ch2 = ch1; ch2 <<= 8; }	return ((ch == 0) ? ch2 : toupper(ch)); } /---/ or /*-*/

unsigned int key(void) {      int ch1 =0, ch2 = 0; unsigned int ch = 0; ch1 = getch // getch returns an int. what we are going to do is deliberately copy this int value to an unsigned int by another call. ch = ch1; // copied the int to an unsigned. if(ch == 0) {          ch2 = getch; // ch2 is an int, getch returns an int. ch = ch2; // deliberately copied the int to an unsigned int. Copying is permissible. ch <<= 8; }       return ch; // what it returns is an unsigned int. unsigned or unsigned int are same. } -

On a 32 bit compiler the int is stored in 4 bytes. On GCC-GNU 32 bit compiler, instead of int a short is acceptable because it is stored in 2 bytes.

The following function will be applicable.

unsigned short int  key(void) {   short ch1,ch2; unsigned short ch;

ch1 = getch; if(ch1 == 0 || ch1 == 224) {       if(ch1 == 224) ch1 = 0; ch2 = getch; ch = ch2 << 8; ch |= ch1; }   else ch = ch1; return ch; } -