|
|
|
| Web Hosting |
![]() ![]() |
Password Function |
Nov 9 2008, 11:10 AM
Post
#1
|
|
|
Premium Member Group: [HOSTED] Posts: 255 Joined: 17-July 08 From: Atlantis Member No.: 31,503 myCENTs:73.77 |
If you are making a logging system in a C++ program you don't want the password you are writing to appear in characters right? making it appear as stars is alot better.
CODE #include<stdio.h> #include<conio.h> char x; void password(char A[]) {int i=0; for(i=0;i<6;i++) {flushall(); x=getch(); A[i]=x; printf("*"); } } void main() { char A[6]; password(A); } First of all declare a character globally or locally inside the function it doesn't matter. But you must declare the array inside the main or globally. The only parameter needed in the function is the array. As for the length for the array, i put it as 6 , you can change it. Notice inside the function it is important to put flushall() to clear to buffer otherwise some leftover characters might rune the password function. Also make sure to put the length of the loop equal to the size of the password. As for how it works its simple, by using the getch() function we get a character,put it in x and then put it in A[0], the process is repeated until the entire array is full. Each time you input a character '*' is printed and the cycle is repeated. You can replace the '*' with X if you want or any other character, but * is used in most programs. The main downer in the way i wrote this function is that it has a fixed length, the password needs to be exactly 6 in this case. And pressing 'Enter' would be considered a character inside the password, you can however fix that by doing a check for the ascci code of the inputed character. I think the ascci code of 'Enter' is 13 if my memory serves me well. This post has been edited by khalilov: Nov 9 2008, 11:11 AM |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
13 | Feelay | 1,153 | 19th December 2008 - 03:43 AM Last post by: laniczech |
|||
![]() |
9 | TavoxPeru | 1,043 | 11th December 2008 - 04:11 PM Last post by: magiccode9 |
|||
![]() |
5 | derouge | 1,536 | 30th November 2008 - 07:16 AM Last post by: iG-Rev.Keith Ratliff |
|||
![]() |
6 | Houdini | 1,848 | 21st November 2008 - 10:37 AM Last post by: magiccode9 |
|||
![]() |
4 | khalilov | 272 | 10th November 2008 - 05:19 PM Last post by: khalilov |
|||
![]() |
0 | CheckProgs | 135 | 12th October 2008 - 02:07 AM Last post by: CheckProgs |
|||
![]() |
3 | FirefoxRocks | 330 | 12th September 2008 - 02:07 AM Last post by: xboxrulz |
|||
![]() |
5 | Mitch666Holland | 427 | 26th August 2008 - 10:28 AM Last post by: yordan |
|||
![]() |
7 | joe.k | 2,482 | 19th August 2008 - 11:53 AM Last post by: Guest |
|||
![]() |
22 | essential_clix | 3,530 | 7th August 2008 - 09:27 PM Last post by: Guest |
|||
![]() |
1 | Emusic.SR.mN | 1,640 | 28th July 2008 - 01:12 AM Last post by: Guest |
|||
![]() |
7 | vizskywalker | 1,507 | 7th July 2008 - 11:03 AM Last post by: TavoxPeru |
|||
![]() |
5 | wutske | 632 | 26th June 2008 - 02:59 PM Last post by: wutske |
|||
![]() |
6 | jedipi | 3,004 | 14th June 2008 - 08:23 AM Last post by: iGuest |
|||
![]() |
3 | tansqrx | 25,466 | 23rd April 2008 - 10:00 PM Last post by: tansqrx |
|||
|
Lo-Fi Version | Time is now: 7th January 2009 - 11:26 PM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Nov 9 2008, 11:10 AM





