Code:
//Program to execute jannat.exe
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
struct date
{
int dd;int mm;int yy;
};
struct masterlist
{
struct date bday;
char name[20];
char name1[20];
char live[10];
char password1[15];
char password2[15];
char col[15];
int key;
};
struct masterlist m;
// int nom=0;
int ch,n=0,flag,ptr,ssize;
// long int msize;
FILE *fp,*ft;
fp=fopen("JANNATINFO.DAT","rb+");
if(fp==NULL)
{
fp=fopen("JANNATINFO.DAT","wb+");
{
if(fp==NULL)
{
printf("\n Cannot Access File!!!");
exit(1);
}
}
}
ssize=sizeof(m);
while(1)
{
printf("\n 1>Create An Account");
printf("\n 2>Log In To An Account");
printf("\n 3>Statistics for a particular month->");
printf("\n 4>Credits");
printf("\n 5>Information about this user");
printf("\n 6>Exit");
printf("\nNow enter your choice->");
scanf("%d",&ch);
switch(ch)
{
case 1: fseek(fp,0,SEEK_CUR);
printf("\n Enter your full name->");
scanf("%s",m.name);
fflush(stdin);
flag=0;
// if(flag==0)
// {
printf("\n %s Please Enter your birthdate(dd/mm/yyyy)",m.name);
scanf("%d%*c%d%%*c%d",&m.bday.dd,&m.bday.mm,&m.bday.yy);
/* if((m.bday.dd<0||m.bday.dd>31)||(m.bday.mm>12||m.bday.mm<0)||(m.bday.yy<1900||m.bday.yy>2011))
{
printf("\n You entered improper date");
printf("\n Try again:");
flag=0;
}
else
flag=1;
} */
printf("\n Enter name of your college:");
fflush(stdin);
scanf("%s",m.col);
fflush(stdin);
printf("\n Enter where you live->");
scanf("%s",m.live);
// puts(m.name);
fflush(stdin);
while(1)
{
printf("\n Enter the password you wish->");
scanf("%s",m.password1);
fflush(stdin);
printf("\n Please retype your password->");
scanf("%s",m.password2);
ptr=strcmp((m.password2),(m.password1));
if(ptr==0)
{
printf("\n Your password is set!!!");
break;
}
else
{
printf("\n Try Again!!!");
continue;
}
}
n++;
printf("\nCongratulations!!! Your Account is successfully registered with Jannat.exe");
printf("\n you are the %d th member",n);
m.key=n;
getch();
system("cls");
break;
case 2: system("cls");
printf("\n <<---------------LOGIN PAGE---------------->>");
printf("\n Enter yor name:");
scanf("%s",m.name1);
printf("\n Entre your Password:");
scanf("%s",m.password2);
rewind(fp);
while(fread(&m,ssize,1,fp)==1)
{
if(strcmp(m.name1,m.name)==0 && strcmp(m.password1,m.password2)==0)
{
printf("\n Welcome Back %s!!We are happy to have you!!!",m.name);
printf("\n You have successfully Logged IN!!");
printf("\n Your membership ID is %d",m.key);
goto control;
break;
}
else
{
printf("\nYou are not Authorised to Enter!!!");
break;
}
control: printf("\n Now here are the list of actions you can do:");
printf("\n 1.View Profile \n 2.Edit Profile \n 3. Enter Bazzar");
printf("'\n 4.Delete Profile \n5.Exit");
printf("\n Enter your Choice->");
scanf("%d",&ch);
do
{
switch(ch)
{
case 2:
printf("\n Enter your full name->");
scanf("%s",m.name);
fflush(stdin);
printf("\n %s Please Enter your birthdate(dd/mm/yyyy)",m.name);
scanf("%d%*c%d%%*c%d",&m.bday.dd,&m.bday.mm,&m.bday.yy);
printf("\n Enter name of your college:");
fflush(stdin);
scanf("%s",m.col);
fflush(stdin);
printf("\n Enter where you live->");
scanf("%s",m.live);
fseek(fp,-ssize,SEEK_CUR);
fwrite(&m,ssize,1,fp);
break;
case 1: printf("\n Your Name-%s",m.name);
printf("\n Your Birthday is-%d/%d/%d",m.bday.dd,m.bday.mm,m.bday.yy);
printf("\n Your Live At-%s",m.live);
printf("\n Name of Your college is-%s",m.col);
break;
/* case 3:entbaz();
break;
case 4:delpro();
break;
case 5:exit(0);
break;*/
default:printf("\n Invalid Choice!!!Try Again");
break;
}
}while(ch!=(5||4));
}
break;
}
}
}
I input correct name and password but getting the message "You are not authorised to Enter".Please help!!