BLOGGER TEMPLATES AND TWITTER BACKGROUNDS

04 August, 2009

Accept a Password string, displaying it as *

This program will accept a string from the user as a password, displaying *'s instead of the data entered by the user.
Lang: C

#include(stdio.h)
#include(conio.h)
#include(string.h)
void main() /* Or int main() with return 0 */
{
char pass[20];
int i;

printf("Enter password: ");
for(i=0; i<20; i+=1)
{
pass[i] = getch();
if(pass[i] == '\r') /* The carriage return escape sequence */
break;
printf("*");
}

pass[i] = '\0';
printf("\n");
if(strcmp(pass, "123")) /* Assume "123" is the correct password */
printf("Correct Password");
else
printf("Wrong Password");

getch();
}

Difficulty Rating: 3/10
For Creative Minds: Try using this with getche() instead of getch(). What changes will you have to make?

19 May, 2009

Introduction to the site

This blog is meant to be a guide for computer programs in various languages. It is not, I repeat, NOT meant to be a definitive database or a place from where you could copy school assignments. Currently Program Matrix has only C, but hopefully C# is soon on its way.

The programs here are meant to be for learners. I will, therefore, provide comparatively easier programs, leaving anything 'high-funda' (as some call it) out. You are still expected to have some basic knowledge of the programming language in question! (And, I'm afraid, a bit advanced too...)

If you are specifically looking for a program, use the search feature at the top. If you still don't find anything, you can always request. I'll try my best to fulfill the same.

As you might already be knowing, there are several methods to write a program to achieve a single objective, and thus, your methods might differ from mine.

Note: Replace the () brackets in the #include directives and any other places as required by <> brackets.