I wrote this program... Just gave a try!!
i got a problem with searching a string in file.. the "checkp" used in the login function, returns a value "1", whereas it must return a value "0" Hence my program fails...
what i felt is, the file i'm opening, "web_reg.txt", in that, extra spaces are coming...
Does anyone knows, to sort this out???? Please help me!!
please check it out in your PC's.
Thanks a lottt
The code is as following:
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct web
{
char name[30],pass[30];
}w;
int n;
void login(void);
void reg(void);
void main()
{
clrscr();
printf("\n\n\n\n\n\t\t\t\tWELCOME TO MY WEBSITE");
printf("\n\t\t\t\t=====================");
printf("\n\n\n\n\t\t\tPress Enter to proceed...!!");
if(getchar()=='\n')
clrscr();
printf("\n\n\n\t\t\t1. LOGIN\t\t2. REGISTER");
printf("\n\n\n\t\t\t\tENTER YOUR CHOICE: ");
scanf("%d",&n);
switch(n)
{
case 1: clrscr();
login();
case 2: clrscr();
reg();
}
}
void reg()
{
FILE *fp;
char c; int i=0;
fp=fopen("Web_reg.txt","ab+");
printf("\n\n\t\t\t\tWELCOME TO REGISTER ZONE");
printf("\n\t\t\t\t^^^^^^^^^^^^^^^^^^^^^^^^");
printf("\n\n\t\t\t\t ENTER USERNAME: ");
scanf("%s",w.name);
printf("\n\n\t\t\t(press spacebar after ryping the pasword)");
printf("\n\n\t\t\t\t DESIRED PASSWORD: ");
while((c=getch())!=' ')
{
w.pass[i++]=c;
printf("%c",'*');
}
fwrite(&w,sizeof(w),1,fp);
fclose(fp);
printf("\n\n\tPress enter if you agree with Username and Password");
if(getchar()=='\n')
{
clrscr();
printf("\n\n\t\tYou are successfully registered");
printf("\n\n\t\tTry login your account??\n\n\t\t ");
printf("> PRESS 1 FOR YES\n\n\t\t > PRESS 2 FOR NO");
scanf("%d",&n);
switch(n)
{
case 1: clrscr();
login();
break;
case 2: clrscr();
printf("\n\n\n\t\t\t\t\tTHANK YOU FOR REGISTERING");
break;
}
}
getch();
}
void login()
{
FILE *fp;
char spc,c,name[30],pass[30]; int i=0;
int checku,checkp;
fp=fopen("Web_reg.txt","rb");
printf("\n\n\t\t\t\tWELCOME TO LOG IN ZONE");
printf("\n\t\t\t\t^^^^^^^^^^^^^^^^^^^^^^");
printf("\n\n\t\t\t\t ENTER USERNAME: ");
scanf("%s",name);
printf("\n\n\t\t\t(press spacebar after ryping the pasword)");
printf("\n\n\t\t\t\t ENTER PASSWORD: ");
while((c=getch())!=' ')
{
pass[i++]=c;
printf("%c",'*');
}
while(!feof(fp))
{
fread(&w,sizeof(w),1,fp);
checku=strcmp(name,w.name);
checkp=strcmp(pass,w.pass);
if(checku==0&&checkp==0)
{
clrscr();
printf("\n\n\n\t\t\tYOU HAVE LOGGED IN SUCCESSFULLY!!");
printf("\n\n\n\t\t\t\tWELCOME, HAVE A NICE DAY");
break;
}
else if(checku==0&&checkp!=0)
{
printf("\n\n\n\t\t\tWRONG PASSWORD!! Not %s??",name);
printf("\n\n\t\t\t\t\t(Press 'Y' to re-login)");
if(getch()=='y'||getch()=='Y')
login();
}
else if(checku!=0&&checkp!=0)
{
printf("\n\n\n\t\t\tYou are not a Registered User\n \t\t\tPress enter to register yourself");
if(getchar()=='\n')
reg();
}
}
getch();
}