Advertisement
jade97

Linked List

Oct 7th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 19.38 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<ctype.h>
  6. typedef struct dt{
  7.                   int aMoney;
  8.         }WD;
  9. typedef struct at{
  10.                    char gender;
  11.                    char FName[10];
  12.                    char MI;
  13.                    char LName[10];
  14.         }Pinfo;
  15. typedef struct bt{
  16.                    char pin[100];
  17.         }Pcode;
  18. typedef struct ct{
  19.                    Pcode code;
  20.                    Pinfo info;
  21.                    WD withD;
  22.                    int idNum;
  23.         }account;
  24. typedef struct nodeT{
  25.     account d;
  26.     struct nodeT *next;
  27. }NODE_T;
  28. void admin(account acc[],int count,NODE_T **LL);
  29. int signIn(account acc[],account container[],int count5);
  30. void createAcc(account acc[], int *count,int size);
  31. int main(void){
  32.      FILE *fp,*fp2;
  33.      fp=fopen("storage.txt","a");
  34.      fp2=fopen("num.txt","r");
  35.      NODE_T *LL;
  36.      int size=5;
  37.      account person[size],strg[size];
  38.      int opt, count,i;
  39.      fscanf(fp2,"%d",&count);
  40.      printf("%d",count);
  41.      printf("*****************************************************************\n");
  42.      printf("\5\tT                                                       \5\n");
  43.      printf("\5\t\tE                                               \5\n");
  44.      printf("\5\t\t\tC                                       \5\n");
  45.      printf("\5\t\t\t\tH                               \5\n");
  46.      printf("\5\t\t\t\t\tS                       \5\n");
  47.      printf("\5\t\t\t\t\t\tC               \5\n");
  48.      printf("\5\t\t\t\t\t\t\tI       \5\n");
  49.      printf("\5\t\t\t      B A N K\t\t\t\t\5\n");
  50.      printf("*****************************************************************\n");
  51.      system("pause");
  52.      system("cls");
  53.      do{
  54.      printf("************************\n");
  55.      printf("* Welcome to TSB!      *\n");
  56.      printf("* \20 1.) User Login     *\n");
  57.      printf("* \20 2.) Admin Login    *\n");
  58.      printf("* \20 3.) Create Account *\n");
  59.      printf("* \20 4.) Exit           *\n");
  60.      printf("************************\n");
  61.       printf("  Input: ");
  62.       fflush(stdin);
  63.      scanf("%d", &opt);
  64.      system("pause");
  65.      system("cls");
  66.      switch(opt){
  67.                case 1: signIn(person,strg,count);//This is where the person will be directed to the Sign In Function
  68.                        break;
  69.                case 2: admin(person,count,&LL);//This is where the person will be directed to the Admin only Function(FILES)
  70.                        break;
  71.                case 3: createAcc(person, &count,size);//This is where the person will be directed to the Creation Function
  72.                        person[count-1].idNum=count;//count2 and count is to keep track of the number of persons
  73.                            fwrite(&person[count-1],sizeof(account),1,fp);//writes the whole structure to admin.txt
  74.                     break;
  75.                case 4: break;
  76.                default: printf("Try Again\n");
  77.                system("pause");
  78.                system("cls");
  79.                }
  80.                }while(opt!=4);
  81.                fclose(fp);
  82.                printf("Thank You for Using Our System!");
  83.     getch();
  84.     return 0;
  85. }
  86. int signIn(account acc[],account container[],int count5){
  87.      FILE *fp,*fp3;
  88.      fp3=fopen("storage.txt","r");
  89.      char s[100],t;
  90.      int m,z,num,pin,i=0,x,count=0, count2,count3=0;
  91.      char opt;
  92.      do{
  93.          z=0;
  94.          t='\b';
  95.          count2=count;
  96.          printf("--SIGN IN--\n");
  97.      printf("Note: Pin code must be 5 digits\n");
  98.      printf("Enter Pin Code:");
  99.      while(t!='\r'){
  100.     t=getch();
  101.     if(t=='\b' && z>0){
  102.         z--;
  103.         putch(t);
  104.         putch(' ');
  105.         putch(t);
  106.     }
  107.     else if(t!='\r' && t!='\b'){
  108.         putch('*');
  109.         s[z]=t;
  110.         z++;
  111.     }
  112.  }
  113.  s[z]='\0';
  114.      if(strlen(s)==5){
  115.          m==0;
  116.                    count3=3;
  117.                   while(fread(&container[i],sizeof(account),1,fp3)){
  118.                    if(strcmp(s,container[i].code.pin)==0){
  119.                                         m=1;
  120.                                         printf("\nLogin Successful!");
  121.                        do{              printf("\n");
  122.                                         system("pause");
  123.                                         system("cls");
  124.                                                 if(container[i].info.gender=='M'||container[i].info.gender=='m'){
  125.                                                      printf("Welcome Mr. ");
  126.                                                    for(x=0;x<strlen(container[i].info.LName);x++){
  127.                                                         if(islower(container[i].info.LName[x])>0){
  128.                                                             printf("%c", toupper(container[i].info.LName[x]));
  129.                                                         }else{
  130.                                                             printf("%c",container[i].info.LName[x]);
  131.                                                         }
  132.                                                                                             }
  133.                                                 }else if(container[i].info.gender=='F'||container[i].info.gender=='f'){
  134.                                                        printf("Welcome Ms. ");
  135.                                                    for(x=0;x<strlen(container[i].info.LName);x++){
  136.                                                         if(islower(container[i].info.LName[x])>0){
  137.                                                             printf("%c", toupper(container[i].info.LName[x]));
  138.                                                         }else{
  139.                                                             printf("%c",container[i].info.LName[x]);
  140.                                                         }
  141.                                                         }
  142.  
  143.                                                       }
  144.                                                 printf("!\n1.) Cash Withdrawal\n");
  145.                                                 printf("2.) Cash Deposit\n");
  146.                                                 printf("3.) Balance Inquiry\n");
  147.                                                 printf("4.) Back to Main Menu\n");
  148.                                                 printf("Input:");
  149.                                                 scanf("%d", &num);
  150.                                                 system("pause");
  151.                                                                             system("cls");
  152.                                                 switch(num){
  153.                                                             case 1: printf("--Cash Withdrawal--\n");
  154.                                                                     if(container[i].withD.aMoney!=0){
  155.                                                                             printf("Enter Valued Amount:");
  156.                                                                             scanf("%d", &num);
  157.                                                                     if(num>container[i].withD.aMoney){
  158.                                                                                             printf("Cannot Withdraw Requested Amount!\n");
  159.                                                                                             }else{
  160.                                                                             fp=fopen("storage.txt","w");
  161.                                                                             container[i].withD.aMoney=container[i].withD.aMoney-num;
  162.                                                                             fwrite(&container[i],sizeof(account),1,fp);
  163.                                                                             fclose(fp);
  164.                                                                             printf("Withdraw Succesful\n");
  165.                                                                                                 }
  166.                                                                             }else{
  167.                                                                                 printf("Insufficient balance\n");
  168.                                                                         }
  169.                                                                  break;
  170.                                                                  case 2: printf("--Cash Deposit--\n");
  171.                                                                             printf("Enter Valued Amount:");
  172.                                                                          scanf("%d", &num);
  173.                                                                          fp=fopen("storage.txt","w");
  174.                                                                          container[i].withD.aMoney=container[i].withD.aMoney+num;
  175.                                                                          fwrite(&container[i],sizeof(account),1,fp);
  176.                                                                          fclose(fp);
  177.                                                                          printf("Deposit Succesful\n");
  178.                                                                  break;
  179.                                                                  case 3: printf("Balance: %d\n", container[i].withD.aMoney);
  180.                                                                       break;
  181.                                                                  case 4:
  182.                                                                             return 0;
  183.                                                                             break;
  184.                                                             default: printf("Try Again!\n");
  185.                                                             }
  186.                                                 printf("Do you want to go back?(Y/N)\n");
  187.                                                                                 printf("Input:");
  188.                                                                                 fflush(stdin);
  189.                                                                                     scanf("%c", &opt);
  190.                                     }while(opt!='N'||opt!='n');
  191.                                     }
  192.                                                 i++;
  193.                                                     }
  194.                                                 }else{
  195.                                                       printf("\nTry Again!(PIN must be 5 digits)\n");
  196.                                                       system("pause");
  197.                                                       system("cls");
  198.                                                        count3++;
  199.                                                       }
  200.                                                       }while(count3!=3);
  201.                                                        if(m==0){
  202.                                                         printf("\nAccount not found!\n");
  203.                                                         system("pause");
  204.                                                         system("cls");
  205.                                                 }
  206.                                                       fclose(fp3);
  207.                   }
  208. void createAcc(account acc[], int *count,int size){
  209.      FILE *fp4;
  210.      fp4=fopen("num.txt","w");
  211.      int num,count2,i,count3=0;
  212.      char pin[100];
  213.      if(*count<=size){
  214.      printf("--CREATE ACCOUNT--\n");
  215.      printf("First Name:");
  216.      fflush(stdin);
  217.      gets(acc[*count].info.FName);
  218.      printf("Middle Initial:");
  219.      fflush(stdin);
  220.      scanf("%c", &acc[*count].info.MI);
  221.      printf("Last Name:");
  222.      fflush(stdin);
  223.      gets(acc[*count].info.LName);
  224.      printf("Gender(M/F):");
  225.      fflush(stdin);
  226.      scanf("%c", &acc[*count].info.gender);
  227.      printf("Enter Amount:");
  228.      scanf("%d", &acc[*count].withD.aMoney);
  229.      do{
  230.      printf("PIN Code(MUST BE 5 DIGITS):");
  231.      fflush(stdin);
  232.      gets(pin);
  233.                    if(strlen(pin)==5){
  234.                        if(*count==0){
  235.                                             count3=3;
  236.                                                           strcpy(acc[*count].code.pin,pin);
  237.                                                           *count=*count+1;
  238.                                                           fprintf(fp4,"%d",*count);
  239.                                                           printf("Account Creation Successful!\n");
  240.                                                           system("pause");
  241.                                                           system("cls");
  242.                                                                                              i=size;
  243.                            }else{
  244.                        for(i=0;i<*count;i++){
  245.                            if(pin!=acc[i].code.pin){
  246.                                   count3=3;
  247.                                                           strcpy(acc[*count].code.pin,pin);
  248.                                                           *count=*count+1;
  249.                                                           fprintf(fp4,"%d",*count);
  250.                                                           printf("Account Creation Successful!\n");
  251.                                                           system("pause");
  252.                                                           system("cls");
  253.                                                                                              i=size;
  254.                            }
  255.                        }
  256.                        }
  257.                                  }else{
  258.                                        printf("Try Again!\n");
  259.                                        system("pause");
  260.                                        system("cls");
  261.                                        count3++;
  262.                                        }
  263.                                  }while(count3!=3);
  264.      }else{
  265.          printf("Can't Create Account. Storage is Full!\n");
  266.          system("pause");
  267.                                                           system("cls");
  268.      }
  269.      fclose(fp4);
  270.      }
  271.  
  272. void admin(account acc[],int count,NODE_T **LL){
  273.     FILE *fp,*fp2;
  274.     NODE_T *trav, *temp, person[100];
  275.     fp=fopen("admin.txt","r");
  276.     account container[100];
  277.     char container2[10],code[10];
  278.     char s[100],t;
  279.     int y,z=0, i=0,x,count2=0;
  280.     if(fp!=NULL){
  281.     fscanf(fp,"%s", &container2);
  282.     }else{
  283.     printf("Error! file not found");
  284.     }
  285.     do{
  286.     y=0;
  287.     t='\b';
  288.     printf("Enter Admin Code:");
  289.     while(t!='\r'){
  290.     t=getch();
  291.     if(t=='\b' && y>0){
  292.         y--;
  293.         putch(t);
  294.         putch(' ');
  295.         putch(t);
  296.     }
  297.     else if(t!='\r' && t!='\b'){
  298.         putch('*');
  299.         s[y]=t;
  300.         y++;
  301.     }
  302.  }
  303.  s[y]='\0';
  304.     if(strcmp(s,container2)==0){
  305.         count2=3;
  306.         printf("\nLogin Successful!\n");
  307.         system("pause");
  308.         system("cls");
  309.         fp2=fopen("storage.txt","r");
  310.     *LL=NULL;
  311.     while(fread(&container[z],sizeof(account),1,fp2)){
  312.     if(*LL == NULL){
  313.                      *LL=(NODE_T *)malloc(sizeof(NODE_T));
  314.                      strcpy((*LL)->d.info.FName, container[z].info.FName);
  315.                      strcpy((*LL)->d.info.LName, container[z].info.LName);
  316.                      strcpy((*LL)->d.code.pin,container[z].code.pin);
  317.                      (*LL)->d.info.MI = container[z].info.MI;
  318.                      (*LL)->d.info.gender = container[z].info.gender;
  319.                      (*LL)->d.withD.aMoney=container[z].withD.aMoney;
  320.                      (*LL)->d.idNum=container[z].idNum;
  321.                      (*LL)->next=NULL;
  322.                      trav=*LL;
  323.                          }else{
  324.                            temp=(NODE_T *)malloc(sizeof(NODE_T));
  325.                             strcpy(temp->d.info.FName, container[z].info.FName);
  326.                             strcpy(temp->d.info.LName, container[z].info.LName);
  327.                             strcpy(temp->d.code.pin,container[z].code.pin);
  328.                             temp->d.info.MI = container[z].info.MI;
  329.                             temp->d.info.gender = container[z].info.gender;
  330.                             temp->d.withD.aMoney=container[z].withD.aMoney;
  331.                             temp->d.idNum=container[z].idNum;
  332.                             temp->next=NULL;
  333.                             trav->next=temp;
  334.                     while(trav->next!=NULL){
  335.                     trav=trav->next;
  336.                      }
  337.  }
  338.  z++;
  339.     }
  340.                            trav=*LL;
  341.                             if(trav==NULL){
  342.                            printf("Storage Empty!\n");
  343.                        }
  344.                            while(trav!=NULL){
  345.                            printf("********************************\n");
  346.                            printf("Account: %d\n", i+1);
  347.                            printf("ID Num: %d\n", trav->d.idNum);
  348.                            printf("FULL NAME: ");
  349.                            for(x=0;x<strlen(trav->d.info.LName);x++){
  350.                                                         if(islower(trav->d.info.LName[x])>0){
  351.                                                             printf("%c", toupper(trav->d.info.LName[x]));
  352.                                                         }else{
  353.                                                             printf("%c",trav->d.info.LName[x]);
  354.                                                         }
  355.                            }
  356.                                                         printf(", ");
  357.                            for(x=0;x<strlen(trav->d.info.FName);x++){
  358.                                                         if(islower(trav->d.info.LName[x])>0){
  359.                                                             printf("%c", toupper(trav->d.info.FName[x]));
  360.                                                         }else{
  361.                                                             printf("%c",trav->d.info.FName[x]);
  362.                                                         }
  363.                            }
  364.                            printf(" ");
  365.                                                         if(islower(trav->d.info.MI)>0){
  366.                                                             printf("%c", toupper(trav->d.info.MI));
  367.                                                         }else{
  368.                                                             printf("%c",trav->d.info.MI);
  369.                                                         }
  370.                                                         printf(".\n");
  371.                            if(trav->d.info.gender=='m'||trav->d.info.gender=='M'){
  372.                            printf("Gender: Male\n");
  373.                            }else{
  374.                                printf("Gender: Female\n");
  375.                            }
  376.                            printf("Balance: %d\n", trav->d.withD.aMoney);
  377.                            printf("Pin Code: %s\n", trav->d.code.pin);
  378.                            trav = trav->next;
  379.                            ++i;
  380.                             printf("********************************\n");
  381.                        }
  382.                        system("pause");
  383.                        system("cls");
  384.                        fclose(fp2);
  385.     }else{
  386.         count2++;
  387.         printf("\nPlease Try Again!\n");
  388.         system("pause");
  389.         system("cls");
  390.         fflush(stdin);
  391.     }
  392.     }while(count2!=3);
  393.     fclose(fp);
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement