Originally Posted by
IceDane
It's really completely and absolutely up to you.
Personally, I'd read it after prompting. That way I can compare the password to the read password as it reads instead of storing the whole list in memory.
hi, this is my new code...i just managed to redo again.
Code:
#include<stdio.h>
main( )
{
FILE *fpassword;
char c, line_buffer[100], user[20];
int pass;
fpassword = fopen("C:\\PASSWD.TXT", "r");
if (fpassword == NULL) printf("File doesn't exist\n");
printf("Enter userid: ");
fgets(user,sizeof(user),stdin);
printf("Enter password: ");
fgets(pass,sizeof(pass),stdin);
while( fgets(line_buffer,sizeof(line_buffer),fpassword) != NULL ) /* read from file while still data available */
{
char ftemp[20], fpass[20], fuser[20];
if( sscanf(line_buffer,"%.20s %.20s %.20s",ftemp,fpass,fuser) != 3 ) /* Make sure we parsed 3 fields from the line */
{
/* Invalid line in file, skip to next one */
}
else /* Otherwise, we got 3 fields */
{
if (user == fuser && pass = fpassword)
printf("User Authorized");
else
printf("User Not Authorized");
exit(0);
}
}
fclose(fpassword);
getchar();
}
there's this error saying that there's invalid lvalue in my assignment.
i think the part of my assignment of user==fuser is wrong? is it wrong?