Hello all
I've got an assignment to make a quiz.
First of all one must be able to create users with a passwords
when the program starts, it ask if you want to create a user/pass or login
creating I've done... it writes all the users to a file
both username and password are max 15 long...
they are written to a binary file :
----15 for username----- 15 for pasword----- (without the trails.. it's just white spaces)
now when I want to test my login. i've got a problem:
I first ask the user to enter pass en login
I save this but the watch of my compiler tells me it just saved what I write and not the 15 long
so during the stringcompare it's logical it doesn't compare:
more info on the script:
let's imagine i enter user1 and pass1
and that inside the file it says user1 and pass1:
Code:#include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> int login(void){ char user[15]; char pass[15]; char temp_user[17]; char temp_pass[17]; int sw_ok=1; FILE *login; clrscr(); printf("\t**********************************************\n"); printf("\t* Login *\n"); printf("\t**********************************************\n"); while (sw_ok) { login=fopen("users.dat", "rb"); printf("username: "); scanf("%15s", user); //according to watch it store "user1" printf("Paswoord: "); scanf("%15s", pass); //according to watch it stores "pass1" while(!feof(login)) { fgets(temp_user,sizeof(user)+1,login); //gets " user1" fgets(temp_pass,sizeof(pass)+1,login); //gets " pass1" if (strcmp(temp_user, user) == 0 && strcmp(temp_pass, pass) ==0) { printf("\nAccess OK\n"); sw_ok=0; } else printf("\incorrect\n"); } } printf("Tataaaa"); return 0; }
thanks for some feedback...



LinkBack URL
About LinkBacks



