/* A general C++ utility file as used in other programs */
/* Developed by HARDEEP SINGH */
/* Copyright: Hardeep Singh, 2001.
All rights reserved.
Email: seeingwithc@hotmail.com
Website: mm.2cent.me
Use freely but this header and copyright notice should remain intact.
*/
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define newpage clrscr()
#define newline printf("\n")
#define clear fflush(stdin)
#define loop for(;;)
enum boolean {false,true};
void readstr(char s[],int maxlen=254)
{
unsigned short i;
unsigned int k;
char *a;
if (maxlen>254) {
cout<<endl<<"Function readstr in module myown.h ";
cout<<"cannot read such a long string.";
return;
}
maxlen++;
a=new char[maxlen+2];
k=(int)&a[0];
a[0]=maxlen;
clear;
asm mov ah,0x0A; //for Turbo C++ for DOS only
asm mov dx,k;
asm int 0x21;
i=(short)(((unsigned short)a[1])%256);
a[2+i]=0;
strcpy(s,&a[2]);
delete a;
newline;
clear;
}
int readint(char m[]="Enter the number",
int low=-32767, int high=32767,
int ll=1, int lh=1)
{
int r,s,e1,e2;
char st[20];
clear;
do {
cout<<endl<<m<<"->";
readstr(st,11);
s=sscanf(st,"%d",&r);
e1=s<1;
e2=(ll && r<low)||(lh && r>high);
if (e1)
cout<<endl<<"Invalid numeric format.";
else if (e2)
cout<<endl<<"Number out of bounds.";
} while (e1 || e2);
return(r);
}