As some of you would already know, I made a program which accepts login and password from users and shows "*" instead of actual password characters.
I know the program is grossly incorrect but I still tried to apply whatever I picked up using books and example programs.

*****DISCLAIMER- I am not an IT wizkid and calling me a beginner would be an extrapolated statement aswell. I am here to learn and discuss and not to be admonished at***************

.
.

#include<stdio.h>
#include<string.h> 
#include<stdlib.h> 
#include<ctype.h> 
#include<math.h> 

void
fnlogincheck();
int main(int argc,char**argv);
{
system("cls");
fnlogincheck();
return 0;
}
void
fnlogincheck();
{
char *pcloginid[3]={"user1","user2","user3"};
char *pcpwd[3]={"Potato","Tomato","Turnip"};
int l,p,i,c;
char login[5];
char password[6];
printf("\n\n\n\n\t\tEmployee Information System\n"); 
printf("\t\t===========================\n\n"); 
printf("\t\tLogin Screen\n"); 
printf("\t\t============\n"); 
printf("\n\t\tEnter User Id\t: ");
scanf("%s",&login);
printf("\n\t\tEnter Password\t: ");
scanf("%s",&password);
}

{
l=strcmp(&loginid[i], login);
p=!strcmp(&pwd[i],password);
for(i=o,i<=3,i++)
}
{
password[c]= password[6]
printf("*");
for(c=0,c<=6,c++)
}
{
if( l=0,p=0)
    printf("LOGIN ACCEPTED");
else 
    printf("LOGIN DENIED");

exit
} 
.
.

compiling errors->


compiling...
practice1.c
- c:\program files\microsoft visual studio\myprojects\practice\practice1.c(11) : error C2449: found '{' at file scope (missing function header?)
- c:\program files\microsoft visual studio\myprojects\practice\practice1.c(15) : error C2059: syntax error : '}'
- c:\program files\microsoft visual studio\myprojects\practice\practice1.c(18) : error C2449: found '{' at file scope (missing function header?)
- c:\program files\microsoft visual studio\myprojects\practice\practice1.c(32) : error C2059: syntax error : '}'
- c:\program files\microsoft visual studio\myprojects\practice\practice1.c(39) : error C2449: found '{' at file scope (missing function header?)
- c:\program files\microsoft visual studio\myprojects\practice\practice1.c(43) : error C2059: syntax error : '}'
Error executing cl.exe.

practice1.obj - 6 error(s), 0 warning(s)

WOW....

I have no idea what you are trying to do but you are WAY over your head.
1: Learn to use "tab"
2: password[c]= password[6] with no ; at the end? (Thatll problably solve 99% of the complying errors
3:
What the fuck is this:

{
l=strcmp(&loginid[i], login);
p=!strcmp(&pwd[i],password);
for(i=o,i<=3,i++)
}

{

Personally I think you come from another programming language that should either stick to it or reread from C manuals.

This complys:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>

void fnlogincheck();
int main(int argc,char**argv)
{
    system("cls");
    fnlogincheck();
    return 0;
}

void fnlogincheck()
{
char *pcloginid[3]={"user1","user2","user3"};
char *pcpwd[3]={"Potato","Tomato","Turnip"};
int l,p,i,c;
char login[5];
char password[6];
printf("\n\n\n\n\t\tEmployee Information System\n");
printf("\t\t===========================\n\n");
printf("\t\tLogin Screen\n");
printf("\t\t============\n");
printf("\n\t\tEnter User Id\t: ");
scanf("%s",&login);
printf("\n\t\tEnter Password\t: ");
scanf("%s",&password);



//l=strcmp(&loginid[i], login);
//p=!strcmp(&pwd[i],password);

password[c]= password[6];
printf("*");
for(c=0;c<=6;c++)

{
if( l=p)
    printf("LOGIN ACCEPTED");
else
    printf("LOGIN DENIED");

exit;
}
}

But again, What the fuck are you trying to do with this code???

This complys:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>

void fnlogincheck();
int main(int argc,char**argv)
{
    system("cls");
    fnlogincheck();
    return 0;
}

void fnlogincheck()
{
char *pcloginid[3]={"user1","user2","user3"};
char *pcpwd[3]={"Potato","Tomato","Turnip"};
int l,p,i,c;
char login[5];
char password[6];
printf("\n\n\n\n\t\tEmployee Information System\n");
printf("\t\t===========================\n\n");
printf("\t\tLogin Screen\n");
printf("\t\t============\n");
printf("\n\t\tEnter User Id\t: ");
scanf("%s",&login);
printf("\n\t\tEnter Password\t: ");
scanf("%s",&password);



//l=strcmp(&loginid[i], login);
//p=!strcmp(&pwd[i],password);

password[c]= password[6];
printf("*");
for(c=0;c<=6;c++)

{
if( l=p)
    printf("LOGIN ACCEPTED");
else
    printf("LOGIN DENIED");

exit;
}
}

But again, What the fuck are you trying to do with this code???

ok...well..we were given this assignment to do a case senitive comaprison for teh password and a case insensitive comparison for the login..and show a "*" when we accept passwords form users..typical like gmail/orkut or for that matter daniweb...

thats what i did..and In my 17 years of studying, I have never ever undergone soft-skills training...so I guess that would account for the logic and syntax deprived code..!!

ofcourse there were examples of programs using logical operands like || but somehow I wanted to make it this way..

one more thins, since strcmp returns ansi c value and for everymatch, it returns 0, shouldnt l and p be equal to o..?

thanks

ahh!!

again, I feel there is a bug in Visual C++ 6.0 because my compiler seems hung-up on the braces!!!!

errors after compiling the above mentioned code-
practice1.c
- C:\Program Files\Microsoft Visual Studio\MyProjects\practice\practice1.c(46) : warning C4550: expression evaluates to a function which is missing an argument list
- C:\Program Files\Microsoft Visual Studio\MyProjects\practice\practice1.c(19) : warning C4101: 'i' : unreferenced local variable
- C:\Program Files\Microsoft Visual Studio\MyProjects\practice\practice1.c(57) : error C2084: function 'int __cdecl main(int ,char ** )' already has a body
- C:\Program Files\Microsoft Visual Studio\MyProjects\practice\practice1.c(64) : error C2084: function 'void __cdecl fnlogincheck()' already has a body
- C:\Program Files\Microsoft Visual Studio\MyProjects\practice\practice1.c(94) : warning C4550: expression evaluates to a function which is missing an argument list
Error executing cl.exe.

practice1.obj - 2 error(s), 3 warning(s)

How can you put p=o?

P is a integer. Do you even know what a integer is?

Even if I (or for that matter anyonw who has reached here) would not be a programmer, I would still know what an integer is!!


The question here is not whether we can allot value like zero to it, but to the best of my knowledge, on making a case insensitive/sensitive comparison for two strings, a differnce is returned if they are not found to be equal..(diffrnce of ansi c values)

Now for both the cases we are comparing strings with unequal lengths, login has a strlen of 5 characters and pwd has 6 characters..

how can we equate l to p?

the whole point of me making l =0 and p=0 was to make sure that l and p accept values which are already defined in the arrays!

still, I might be wrong, feel free to correct me.

and why cant 0 be allotted to an integer, initializing loops and allotting null to an integer always involves setting pointers on zero!

There are quite a lot of mistakes in your program (still!). So instead of pointing out each and every of them, I just whipped up my own code and have offered explanations through comments.

#include <stdio.h>
#include <conio.h>
#include <string.h>


int main()
{

    char *loginID[] = {"user1", "user2", "user3"};
    char *passwords[] = {"pass1", "pass2", "pass3"};
    char login[6];
    char pass[6], temp;
    int i, loginNumber;
    printf("Enter the login id\n");
    fgets(login,6,stdin); // Use fgets instead of gets or scanf(%s)
    for(i=0; i < 3; i++) // Need to see if the entered login ID is any one of the three login IDs
    {
        if(!strcmpi(loginID[i],login)) //strcmpi() ignores case
            break;
    }
    if(i == 3) //If the login ID didn't match in any of the three cases
    {
        printf("Invalid login id\n");
        getchar();
        exit(0);
    }

    loginNumber = i; //need to store the subscript of the login ID
    login[6] = '\0'; //NULL terminated string
    printf("Enter the password\n");
    while((temp = getc(stdin)) != '\n') // flush the input. Google it! Don't use fflush(stdin)
    ;

    for(i=0; (temp = getch()) != '\r'; i++) //Loop executes till 'enter' is pressed
    {
        printf("*");
        pass[i] = temp;// store character in pass
    }
    pass[6] = '\0';
    if(!strcmp(passwords[loginNumber], pass))//compare with the appropriate loginID. Use strcmp
    {
        printf("\nAccess granted!\n");
        getchar();
        exit(0);
    }
    else
    {
        printf("\nAccess denied!\n");
        getchar();
        exit(0);
    }
    return 0;
}

The above code is still a li'l crappy since it uses non-portable getch(). I couldn't figure out any other way of getting the password without it being echoed to the screen. Maybe someone else will show a way.

The reason for not using scanf(or gets) can be found here. You can read other related articles too over there.

There are quite a lot of mistakes in your program (still!). So instead of pointing out each and every of them, I just whipped up my own code and have offered explanations through comments.

#include <stdio.h>
#include <conio.h>
#include <string.h>


int main()
{

    char *loginID[] = {"user1", "user2", "user3"};
    char *passwords[] = {"pass1", "pass2", "pass3"};
    char login[6];
    char pass[6], temp;
    int i, loginNumber;
    printf("Enter the login id\n");
    fgets(login,6,stdin); // Use fgets instead of gets or scanf(%s)
    for(i=0; i < 3; i++) // Need to see if the entered login ID is any one of the three login IDs
    {
        if(!strcmpi(loginID[i],login)) //strcmpi() ignores case
            break;
    }
    if(i == 3) //If the login ID didn't match in any of the three cases
    {
        printf("Invalid login id\n");
        getchar();
        exit(0);
    }

    loginNumber = i; //need to store the subscript of the login ID
    login[6] = '\0'; //NULL terminated string
    printf("Enter the password\n");
    while((temp = getc(stdin)) != '\n') // flush the input. Google it! Don't use fflush(stdin)
    ;

    for(i=0; (temp = getch()) != '\r'; i++) //Loop executes till 'enter' is pressed
    {
        printf("*");
        pass[i] = temp;// store character in pass
    }
    pass[6] = '\0';
    if(!strcmp(passwords[loginNumber], pass))//compare with the appropriate loginID. Use strcmp
    {
        printf("\nAccess granted!\n");
        getchar();
        exit(0);
    }
    else
    {
        printf("\nAccess denied!\n");
        getchar();
        exit(0);
    }
    return 0;
}

The above code is still a li'l crappy since it uses non-portable getch(). I couldn't figure out any other way of getting the password without it being echoed to the screen. Maybe someone else will show a way.

The reason for not using scanf(or gets) can be found here. You can read other related articles too over there.

omg..!!

well..thanks a ton..!!

I will refer to google for understanding the comments and find their explanations..I am still trying to comprehend this program and what all was edited in it..!

thnx again...i shall disturb you again with my problem if any..

This article has been dead for over six months. Start a new discussion instead.