Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how make password...? Posted by richardbautist on 1 Feb 2007 at 9:41 PM
I need to know something..
How to make a C program that will let user type any words but when they are typing they can not see what they are typing they only see asterisk (*) for example: they will type hello the output in the screen is ***** like that like the principle in passwords.


Thanks for the someone that will help me :)
Report
Re: how make password...? Posted by MT2002 on 1 Feb 2007 at 9:53 PM
: I need to know something..
: How to make a C program that will let user type any words but when they are typing they can not see what they are typing they only see asterisk (*) for example: they will type hello the output in the screen is ***** like that like the principle in passwords.
:
:
: Thanks for the someone that will help me :)
:

You are referring to recieving input without echo (ie, getting input without displaying it). This will allow your program to output another character (or not) in its place (as the *)

There is no standard way to do this. With borland compilers, you can use getche. With MSVC++ you will need to use the Win32 API Console routines.

What compiler are you using?

Report
Re: how make password...? Posted by richardbautist on 1 Feb 2007 at 10:09 PM
tnx for replying by the way i am using TURBO C... and what i am saying is that when somebody is typing he can not see the letters but only asterisk (*)... when he type a wrong word it will display wrong code but if its correct the program will say "Its right"
pls help me
Report
Re: how make password...? Posted by MT2002 on 1 Feb 2007 at 10:49 PM
This message was edited by MT2002 at 2007-2-1 22:53:35

: tnx for replying by the way i am using TURBO C... and what i am saying is that when somebody is typing he can not see the letters but only asterisk (*)... when he type a wrong word it will display wrong code but if its correct the program will say "Its right"
: pls help me
:

You can use getche() in a loop..
char pass[10];
memset (pass,0,10); //clear string

for (int i=0; i<10; i++) {

   char c=getche();
   if (c=='\n')  //break if newline
      break;
   pass[i]=c;
   printf ("*");
}

I dont have TurboC atm, but this should work just fine. This loop will break if either a)user enters newline char, or more then 10 chars entered.

Please note that getche() is Borland specific.

Also, you can use the strcmp() routine from string.h to compare if two strings match.

Also, This code is C NOT C++. (I know TurboC 2.1 doesnt support C++)
If you need a C++ version, let us know.

Hope this helps;





Report
Re: how make password...? Posted by richardbautist on 2 Feb 2007 at 3:27 AM
Thanks for your replies and im sorry that i disturbed you too much... :(
Because im still a student and our subject is only C Language and my teacher required us to use only Turbo C program... he requires us to do a program (password.c)... hope u can help me again TNX a LOT... GOD BLESS YOUR LIFE !!!

Report
Re: how make password...? Posted by MT2002 on 2 Feb 2007 at 4:41 AM
: Thanks for your replies and im sorry that i disturbed you too much... :(

No worry--Its fun. Gives me something to do

: Because im still a student and our subject is only C Language and my teacher required us to use only Turbo C program... he requires us to do a program (password.c)... hope u can help me again TNX a LOT... GOD BLESS YOUR LIFE !!!
:

getche() is the way to go...
#include <stdio.h>
#include <conio.h>
#include <string.h>

#define PASS_SIZE 10

int main (int argc, char** argv) {

   char cCur=0;
   char Password[PASS_SIZE+1] = "Password\0\0"; /*actual password*/
   int i=0;

   char strPass[PASS_SIZE+1];

   /* null out our string */
   memset (strPass, 0, PASS_SIZE);

   /* get password */
   for (i=0; i<PASS_SIZE; i++) {

      char c=getche ();
      if (c=='\n' || c=='\r') /* watch for NL/CR feed */
         break;
      strPass[i]=c;
      putch ("*");
   }
   strPass[i+1]='\0'; /* add null terminator */

   /* compare passwords */
   if (strcmp (strPass, Password)==0) {

      /* passwords match */
   }

   return 0;
}

Not compiled nor tested. This should work however. Either way, the concept is still the same.

Report
getche() actually prints what is typed... Posted by AsmGuru62 on 2 Feb 2007 at 5:06 AM
You need the pair getch()/putch('*') to do this.
Report
Re: getche() actually prints what is typed... Posted by MT2002 on 2 Feb 2007 at 5:36 AM
: You need the pair getch()/putch('*') to do this.
:

You are correct--my bad. Havnt worked with DOS is awhile

Report
WHAT ??? I CAN'T GET THE TWO OF YOU !!! Posted by richardbautist on 2 Feb 2007 at 5:55 AM

how to pair that what shud i do? write?
Report
Re: WHAT ??? I CAN'T GET THE TWO OF YOU !!! Posted by MT2002 on 2 Feb 2007 at 6:12 AM
:
: how to pair that what shud i do? write?
:
Try this...
#include <stdio.h>
#include <conio.h>

#define PASS_MAX 10

int main () {

	char pass[PASS_MAX+1];
	int i=0;

	memset (pass,0,PASS_MAX+1);
	clrscr ();

	for (i=0; i<PASS_MAX; i++) {

	    char c=getch();
	    if (c=='\n' || c=='\r')
		break;
	    pass[i]=c;
	    putch ('*');
	}

	if (! strcmp (pass, "Password"))
	   printf ("\nWelcome");

	getch();
	return 0;
}

If the user types in "Password" a greeting message is displayed.

After the user types the password, the program waits for any key to teminate.

Report
Re: WHAT ??? I CAN'T GET THE TWO OF YOU !!! Posted by richardbautist on 2 Feb 2007 at 6:21 AM
Thanks for the codes you gave me... it worked with TURBO C 2.01 !!!
that's all for now...
maybe i can ask you more difficult again next time...

gudnyt

:)

just help me with my other posts okay??

thanks :)
Report
Re: how make password...? Posted by Harshit Godha on 2 Feb 2007 at 9:50 AM
: I need to know something..
............ ............... help me :)
:

In my view you can use getch(); function available in conio.h
Try this

temp = getch();
cout << "*";

note that getch returns int value.

Harshit
Report
Re: how make password...? Posted by MT2002 on 2 Feb 2007 at 10:20 AM
: : I need to know something..
: ............ ............... help me :)
: :
:
: In my view you can use getch(); function available in conio.h
: Try this
:
: temp = getch();
: cout << "*";
:
: note that getch returns int value.
:
: Harshit
:

The OP was using TurboC 2.1, an old DOS C compilier IDE. This compilier does not support C++ synthax (ie, std::cout). In fact, it doesnt even support all of ANSI C synthax.

Also, if one is using C++, one should *never* use conio.h, as there is no need for it in modern compiliers. TurboC 2.01 (I believe) was pre ANSI, so it is a noncompilent compilier (Which is why it is not to par with ANSI C)

Report
Re: how make password...? Posted by Harshit Godha on 2 Feb 2007 at 11:31 AM
: : : I need to know something..
: : ............ ............... help me :)
: : :
: :
: : In my view you can use getch(); function available in conio.h
: : Try this
: :
: : temp = getch();
: : cout << "*";
: :
: : note that getch returns int value.
: :
: : Harshit
: :
:
: The OP was using TurboC 2.1, an old DOS C compilier IDE. This compilier does not support C++ synthax (ie, std::cout). In fact, it doesnt even support all of ANSI C synthax.
:
: Also, if one is using C++, one should *never* use conio.h, as there is no need for it in modern compiliers. TurboC 2.01 (I believe) was pre ANSI, so it is a noncompilent compilier (Which is why it is not to par with ANSI C)
:

:


Hey thanx for reply
but i know a very little abt versions newer then 2.1
although i am in BE 3rd yr
can you pls tell me more
u can mail me too

Report
Re: how make password...? Posted by MT2002 on 2 Feb 2007 at 11:56 AM
This message was edited by MT2002 at 2007-2-2 12:1:18

: : : : I need to know something..
: : : ............ ............... help me :)
: : : :
: : :
: : : In my view you can use getch(); function available in conio.h
: : : Try this
: : :
: : : temp = getch();
: : : cout << "*";
: : :
: : : note that getch returns int value.
: : :
: : : Harshit
: : :
: :
: : The OP was using TurboC 2.1, an old DOS C compilier IDE. This compilier does not support C++ synthax (ie, std::cout). In fact, it doesnt even support all of ANSI C synthax.
: :
: : Also, if one is using C++, one should *never* use conio.h, as there is no need for it in modern compiliers. TurboC 2.01 (I believe) was pre ANSI, so it is a noncompilent compilier (Which is why it is not to par with ANSI C)
: :

: :
:
:
: Hey thanx for reply
: but i know a very little abt versions newer then 2.1
: although i am in BE 3rd yr
: can you pls tell me more
: u can mail me too
:

What do you need to know? I like Turbo C 2.01 (because of dos.h, it can allow direct access to hardware via interrupts/ports etc without being interrupted by Windows). Turbo C 2.01 was developed way back when PC real mode was standard (I believe so, anyway--I could be wrong). It was developed more then a decade ago.

Windows runs under protected mode and does not allow 32 bit instructions this. Because TurboC 2.01 produces 16bit real mode apps, it is emulated as such, and does have direct access. (Alot of DOS games used 32bit far pointers directly to video memory, for example)

Nontheless, TurboC 2.01 is Pre ANSI C--It doesnt even support the bool data type! For almost all development envirements, TurboC 2.01, as being pre ANSI-compilent (not up to standards) is rairley used for real world applications. Did I mention it is *very* non portable?
And, as being a primitive set of tools, includes an "okay" debugger (forget breakpoints), and does not produce the best code. Also, you can forget a good profilier with TurboC 2.01.

With that, anyone could use embedded 16bit x86 assembly to emulate the power of TurboC's dos and bios libraries, so their is no need for it anymore.

--------------

Turbo C is a great compilier for learning low level details without having to go through x86 asm. TurboC was my first compilier IDE, and I learned how low level graphics were implimented by using TurboC.

For real applications (or even learning a language).. ...no.

This is my opionion of course.



Report
Re: how make password...? Posted by AsmGuru62 on 3 Feb 2007 at 5:29 AM
:
: For real applications (or even learning a language).. ...no.
:
: This is my opionion of course.


TC bring back some nostalgia - I used it (all versions) from 1988 to 1995 - wrote a piles of code, including complex graphics editors and database systems.

When DOS was still alive - I am sure it was used to write the real applications. Well... life goes on - now we will have fun with XAML!

Report
Re: how make password...? Posted by Lundin on 5 Feb 2007 at 12:48 AM

: Hey thanx for reply
: but i know a very little abt versions newer then 2.1
: although i am in BE 3rd yr



I really really hope BE != Bachelor in Engineering.
Because then you are in big trouble. Anyone using TC2 for teaching is pretty much clueless about 1) ISO C/C++ standards 2) What skills the market ask for.
Report
Re: how make password...? Posted by Lundin on 5 Feb 2007 at 12:52 AM
:
: Nontheless, TurboC 2.01 is Pre ANSI C--It doesnt even support the bool data type!



That might be because TC2 is C only (not C++) and bool has never been part of ANSI C.

Report
Re: how make password...? Posted by HarshitGodha on 5 Feb 2007 at 8:12 AM
:
: : Hey thanx for reply
: : but i know a very little abt versions newer then 2.1
: : although i am in BE 3rd yr
:

:
:
: I really really hope BE != Bachelor in Engineering.
: Because then you are in big trouble. Anyone using TC2 for teaching is pretty much clueless about 1) ISO C/C++ standards 2) What skills the market ask for.
:

Actually BE = Bachelor in Engineering.
but we used Tc3.0 compiler and i just know the basic c & cpp functions supported by it.
I have No idea of any other compilers.
i think i have no knlodge of c in comparison to u people.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.