Pass box function

To use this function in your program, all you have to do is to follow the below given steps.

Step 1: Include the following header files in your program for this function to work with your


#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

Step 2: Copy the pass_box function above your code to access it from within your program.


/**

* Pass_box() Function

* ========================

*

* Created by: Abhay Jatin Doshi

* Date created: May 20, 2015

* Last Modified: 12:14 23 May 2015

*

* -> The method pass_box can be used to make a CUI(Character User Interface) to get password input

* -> Supports C and C++

* -> This code was running successfully in the Turbo C++ IDE 3.0

* -> For more details: www.encryptorcode.wordpress.com

*

* Steps:

* 1. #include<stdio.h> -> include standard input output file

* 2. #include<conio.h> -> include conserved input output file

* 3. #include<stdlib.h> -> include standard library header file

* 4. It also requires the draw_box() function

* 5. Copy the pass_box() code into your program

* 6. Use pass_box with the following syntax

*

* Syntax:

* pass_box(x,y,n,c)

* x -> x-coordinate of the first option

* y -> y-coordinate of the first option

* n -> number of characters

* c -> char to replace with the original(normally * is used)

*

* Return variables:

* This function returns the input given by the user

* if c[0] = 27 -> esc key was pressed while typing

**/

char* pass_box(int x, int y, int no_char, char c){

//outline of the box

draw_box(x-1,y-1,x+no_char+1,y+1,1);

gotoxy(x,y);

//initialization

char ch;

char *str = (char*) malloc(no_char);

int pos = 0, count = 0;

for(;;){

gotoxy(x+pos,y);

ch = getch();

//esc key

if(ch == 27){

str[0] = 27;

return str;

}

//backspace key

else if(ch == 8){

if(pos == 0) continue;

pos--;

printf("\b \b");

for(int i = pos; i = pos ; i--){

str[i+1] = str[i];

gotoxy(x+i+1,y);

printf("%c",c);

}

str[pos] = ch;

str[count+1] = 0;

pos++;

count++;

}

}

}

Following are some snaps of the output screen

This slideshow requires JavaScript.

One Comment Add yours

Leave a comment