Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anybody familiars with old DOS-apps?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi everyone,

I just came across an old DOS-apps program written in C.
Anyway, It has two so-called textboxes, which will take 2 string inputs (one for username, and the other one for password). Each input is at most 8 characters, so when you enter the first textbox with 8 chars already, the cursor will sit still and the program does not response to additional keyboard input, except for backspace (delete the character) and enter (go to the second textbox).
The second textbox behaves the same, except when you click enter, it will try to match username and password you have just filled.

I'm just curious how to draw all the graphics, and do the "limiting input" to only 8 characters.

Thanks ppl!

 
in case u post the source, u r bound to get some help.
 
graphics part is cool, it can be easily implemnted by just drawing a rectangle, for textbox(in this case only 8 characters are allowed) can also be easily implemnted see my code (well it is rough one but servs purpose)

whole thing is simple just take one character at a time by getch() (does not echos) check the character if it a command (like in this case 'TAB', 'ENTER', or 'BACKSPACE' keys only) process them else depend upon the type (0 or 1) either print the charcter or *.

after your eight character limit is finished ignore all the characters entered.

Hope it helps
Rahul



int maxsize=8;
int type=0; // 0 for text; 1 for password *

char * textbox()
{
int i,j;
char * str=(char*)malloc(maxsize*sizeof(char));
char ch;

//main loop

for(i=0,j=0;i<=maxsize;i++,j++){

ch=getch();

//break the loop if enter or tab is pressed
if( (int)ch == 13 || (int)ch== 9)
break;

//if it is a backspace then move a step back if a first position then no need to move back
if((int)ch == 8){
if(i==0){
i--;
j--;
continue;
}
else{

printf(&quot;\b&quot;);
j-=2;
i-=2;
continue;
}

}

//release control only if enter or tab is pressed else stand there

if(i==maxsize){
i--;
j--;
continue;
}

//if type is 0 print text
if(type==0)
printf(&quot;%c&quot;,ch);
//if type is 1 print *
if(type==1)
printf(&quot;*&quot;);
//store in the buffer
str=ch;
}

//main loop ends here so we have user entered string

//add null at the end of buffer.
str='\0';
printf(&quot;\n%s&quot;,str);

return str;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top