Vous êtes sur la page 1sur 9

HEADER FILE :

#ifndef HEAD_H #define HEAD_H #endif #include<stdio.h> #include<stdlib.h> #include<string.h> #pragma pack(1) typedef struct account{ char name[30]; char pass[20]; char user[20]; int accno; float bal; char contact[14]; char mail[20]; char add[5][20]; int secq; char secans[20]; }account; extern void newacc(); extern void fpasswd(); extern void login(); extern int mainscreen(account *);

APPLICATION FILE :

#include"head.h" char *secques[]={ "1) What is the name of your pet?", "2) What is your favorite sport?", "3) What is the name of your 1st school?", "4) What is the name of your birthplace?" }; int total; int main(){ int op; printf("%d",sizeof(account)); for(;;){ system("clear"); printf("\t\t\t\t\t\tWELCOME TO THE BANK\n"); printf("\t\t\t\t\t\t==================\n\n\n\n"); printf("\n\t1)Login\n\n\t2)Create New Account\n\n\t3)Forgot Password\n\n\t4)Exit\n\t"); scanf("%d",&op); switch(op){ case 1: login();break; case 2: newacc();break; case 3: fpasswd();break; case 4: exit(0); } } return 0; }

LIBRARY FILE :

#include"head.h" extern char *secques[]; int total; void newacc(){ int choice,data,i,temp=0,c; account acc,*a; FILE *fp,*fp2; fp2=fopen("size.acc","r+"); if(fp2==NULL){ fp2=fopen("size.acc","w+"); fprintf(fp2,"%d",total); fclose(fp2); } else{ fscanf(fp2,"%d",&total); fclose(fp2); } system("clear"); printf("\t\t\t\t\t\tPLEASE FILL IN THE FOLLOWING DETAILS :\n\n\n\n"); if(temp!=0) printf("\n\tThe username already exists. Enter a different username\n"); printf("\n\tEnter your full name : "); __fpurge(stdin); gets(acc.name); printf("\n\tEnter the username that you want to use :"); gets(acc.user); if(total!=0){ a=(account *)malloc(total*sizeof(account)); fp=fopen("accounts.acc","r+"); fread(a,sizeof(account),total,fp); fcloseall(); for(i=0;i<total;i++){ int cmp=strcmp((a+i)->user,acc.user); if(cmp==0){ ++temp; system("clear"); newacc(); } } } printf("\n\tEnter the password :");

gets(acc.pass); printf("\n\tEnter your contact no. :"); gets(acc.contact); printf("\n\tEnter your email-id :"); gets(acc.mail); printf("\n\tEnter your address (5 lines):\n\t"); for(i=0;i<5;i++){ gets(acc.add[i]); printf("\t"); } printf("\n\tEnter the starting amount : "); __fpurge(stdin); scanf("%f",&acc.bal); printf("\n\tSelect a security question from below :\n\n\t"); for(i=0;i<4;i++){ puts(secques[i]); printf("\n\t"); } scanf("%d",&acc.secq); printf("\n\tEnter the answer to the security question : "); __fpurge(stdin); gets(acc.secans); acc.accno=1000000000+rand()%1000; if(total==0){ fp=fopen("accounts.acc","w+"); } else{ fp=fopen("accounts.acc","a+"); } fwrite(&acc,sizeof(account),1,fp); fclose(fp); total=total+1; fp2=fopen("size.acc","w+"); fprintf(fp2,"%d",total); fclose(fp2); system("clear"); printf("\n\tCongratulations!!! Your account has successfully been created!!!\n"); printf("\n\n\n\n\n\n\n\n\n\tPress 'b' to go to the main menu\n"); while((c=getchar())!='b'); return; } void login(){ int total,temp=0,i,c,j,ret,cmp,cmp2; FILE *fp,*fp2; char u[30],p[30]; account *a;

fp2=fopen("size.acc","r+"); if(fp2==NULL){ system("clear"); printf("\n\t\t\t\t\t\tNo account has been created\n"); printf("\n\tPress 'b' to go back :\n"); while((c=getchar())!='b'); return; } else{ fscanf(fp2,"%d",&total); fclose(fp2); } system("clear"); printf("\t\t\t\t\t\tENTER THE LOGIN DETAILS\n\n\n\n\n"); printf("\t\t\tUsename : "); __fpurge(stdin); gets(u); printf("\n\t\t\tPassword : "); gets(p); if(total!=0){ a=(account *)malloc(total*sizeof(account)); fp=fopen("accounts.acc","r+"); fread(a,sizeof(account),total,fp); fcloseall(); for(i=0;i<total;i++){ cmp=strcmp((a+i)->user,u); if(cmp==0){ if((cmp2=strcmp((a+i)->pass,p))!=0){ printf("\n\tInvalid Password\n\n\n"); printf("\n\tPress 'b' to go back to login page\n"); while((c=getchar())!='b'); login(); } else{ ret=mainscreen(a+i); break; } } } } if((cmp!=0)&&(i==total)){ printf("\n\n\tThis Username doesnt exist\n\t"); printf("\n\tPress 'b' to go back to login page\n"); while((c=getchar())!='b'); main(); }

if(ret==0){ j=i; for(;i<total-(j+1);i++){ *(a+i)=*(a+i+1); } system("clear"); printf("\n\n\tYour Account has Successfully Been Deleted.. Hope to see you again!!\n\n\t"); printf("\n\n\n\n\n\n\n\tPress 'b' to go back\n"); while((c=getchar())!='b'); main(); } fp=fopen("accounts.acc","w+"); fwrite(a,sizeof(account),total,fp); fclose(fp); system("clear"); return; } int mainscreen(account *p){ int op,c; float dep,with; char pas[20]; for(;;){ system("clear"); printf("\t\t\t\t\t\tWELCOME TO THE BANK\n"); printf("\t\t\t\t\t\t===================\n\n\n\t"); printf("\n\tAccount No. : %d",p->accno); printf("\t\t\t\t\t\t\tNAME : "); puts(p->name); printf("\n\tE-mail id : "); puts(p->mail); printf("\t\t\t\t\t\t\t\t\t\t\tContact No. : "); puts(p->contact); printf("\n\n\tSelect any one option from below\n"); printf("\n\t1) Balance Enquiry\n\t2) Cash deposit\n\t3) Cash withdrawl\n\t4) New Offers\n\t5) Change Password\n\t6) Close Account\n\t7) Exit\n\t"); __fpurge(stdin); scanf("%d",&op); switch(op){ case 1: system("clear"); printf("\n\n\tYour Current Balance is : Rs.%.2f\n\n\n\n\n\n\n\n\tPress 'b' to go back\n",p->bal); while((c=getchar())!='b'); break; case 2: system("clear"); printf("\n\n\tPlease enter the amount you want to deposit : Rs. ");

scanf("%f",&dep); p->bal=p->bal+dep; printf("\n\n\n\n\n\n\n\tPress 'b' to go back\n"); while((c=getchar())!='b'); break; case 3: system("clear"); printf("\n\n\tPlease enter the amount you want to withdraw : Rs. "); scanf("%f",&with); if(with>p->bal){ printf("\n\tERROR : The withdrawl amount is greater than your balance\n\t"); } else{ p->bal=p->bal-with; printf("\n\tThe withdrawl was successful"); } printf("\n\n\n\n\n\n\n\tPress 'b' to go back\n"); while((c=getchar())!='b'); break; case 4: system("clear"); printf("\n\n\tNEW OFFERS!!!!\n"); printf("\t==============\n"); printf("\n\tasadfasf\n"); printf("\n\n\n\n\n\n\n\tPress 'b' to go back\n"); while((c=getchar())!='b'); break; case 5: system("clear"); printf("\n\n\tEnter the old password : "); __fpurge(stdin); gets(pas); if(strcmp(p->pass,pas)!=0) printf("\n\n\tERROR : You entered an invalid password\n"); else{ printf("\n\tEnter the new password : "); gets(pas); strcpy(p->pass,pas); printf("\n\n\tYour password has been changed successfully!!!\n"); } printf("\n\n\n\n\n\n\n\tPress 'b' to go back\n"); while((c=getchar())!='b'); break; case 6: system("clear"); c=0; __fpurge(stdin); printf("\n\n\tAre you sure you want to delete your account??\n"); c=getchar();

if((c=='y')||(c=='Y')) return 0; else break; case 7: return 1234;break; } } } void fpasswd(){ int total,temp=0,i,c,j,ret,cmp,cmp2; FILE *fp,*fp2; char u[30],p[30]; account *a; fp2=fopen("size.acc","r+"); if(fp2==NULL){ system("clear"); printf("\n\t\t\t\t\t\tNo account has been created\n"); printf("\n\tPress 'b' to go back :\n"); while((c=getchar())!='b'); return; } else{ fscanf(fp2,"%d",&total); fclose(fp2); } system("clear"); printf("\n\n\tEnter the username : "); __fpurge(stdin); gets(u); if(total!=0){ a=(account *)malloc(total*sizeof(account)); fp=fopen("accounts.acc","r+"); fread(a,sizeof(account),total,fp); fcloseall(); for(i=0;i<total;i++){ cmp=strcmp((a+i)->user,u); if(cmp==0){ printf("\n\n\tPlease answer your security question : \n\n\t"); j=(a+i)->secq-1; puts(secques[j]); printf("\n\tAnswer : "); gets(p); cmp2=strcmp((a+i)->secans,p); if(cmp2==0){ printf("\n\tYour password is : \n\t"); puts((a+i)->pass);

printf("\n\tPress 'b' to go to main menu\n"); while((c=getchar())!='b'); return; } else{ printf("\n\n\tERROR : Incorrect answer to the security question..\n"); printf("\n\tPress 'b' to go to main menu\n"); while((c=getchar())!='b'); return; } } } } if((cmp!=0)&&(i=total)){ printf("\n\n\tThis Username doesnt exist\n\t"); printf("\n\tPress 'b' to go back to login page\n"); while((c=getchar())!='b'); login(); } return; } ________________________________________________________________________

Vous aimerez peut-être aussi