Advertisement
Radoan_Ahmed

Untitled

Dec 8th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.28 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<windows.h>
  4.  
  5. typedef struct data
  6. {
  7.     int acc_no,age;
  8.     char name[20];
  9.     char address[20];
  10.     char citizenship[20];
  11.     int acc_type;
  12.     double phone;
  13.     struct data *pre;
  14.     struct data *next;
  15. }data;
  16.  
  17. data *head = NULL;
  18. data *list;
  19.  
  20. void new_acc()
  21. {
  22.     int chose,account_number;
  23.     FILE *ptr;
  24.     ptr = fopen("riyad.dat","a");
  25.  
  26.     data *N = (data*)malloc(sizeof(data));
  27.     printf("Enter your name: ");
  28.     scanf(" %[^\n]s",N -> name);
  29.     printf("\nEnter your address: ");
  30.     scanf(" %[^\n]s",N -> address);
  31.     printf("\nEnter your citizenship: ");
  32.     scanf(" %[^\n]s",N -> citizenship);
  33.     printf("\nEnter your acc_no: ");
  34.     scanf("%d",& N -> acc_no);
  35.     printf("\nEnter your age: ");
  36.     scanf("%d",& N -> age);
  37.     printf("\nEnter your acc_type: ");
  38.     scanf("%d",& N -> acc_type);
  39.     printf("\nEnter your phone: ");
  40.     scanf("%lf",& N -> phone);
  41.     N -> pre = NULL;
  42.     N -> next = NULL;
  43.     if(list == NULL)
  44.     {
  45.         list = N;
  46.         head = list;
  47.     }
  48.     else
  49.     {
  50.         list -> next = N;
  51.         N -> pre = list;
  52.         list = list -> next;
  53.     }
  54.     account_number = list -> acc_no;
  55.     fscanf(ptr,"%d %s %s %s %d %d %lf",&account_number,list ->name, list ->address ,list ->address ,&list ->acc_type,&list ->age,&list ->phone);
  56.     fprintf(ptr,"%d %s %s %s %d %d %lf",account_number,list -> name,list -> address,list -> citizenship,list -> age, list -> acc_type,list -> phone);
  57.     fclose(ptr);
  58.     printf("Account create successfully!");
  59.     add_invalid:
  60.     printf("Enter 1 for goto menu 0 for exit");
  61.     scanf("%d",&chose);
  62.     if(chose == 1)
  63.     {
  64.         menu();
  65.     }
  66.     else if(chose == 0)
  67.     {
  68.         printf("Thank you for use our project");
  69.     }
  70.     else
  71.     {
  72.         printf("Invalid input!");
  73.         goto add_invalid;
  74.     }
  75.  
  76.  
  77. }
  78.  
  79.  
  80. void edit_acc()
  81. {
  82.  
  83.     data *temp;
  84.     int account_number,chose,test = 0,account_no;
  85.     printf("Enter the account number whose info you want to change: ");
  86.     scanf("%d",&account_no);
  87.     FILE *old;
  88.     FILE *new;
  89.     old = fopen("riyad.dat","r");
  90.     new = fopen("riyadnew.dat","w");
  91.     list = head;
  92.    /* while(list != NULL)
  93.     {
  94.         if(list -> acc_no == account_no)
  95.         {
  96.             temp = list;
  97.         }
  98.         list = list -> next;
  99.     }*/
  100.     while(fscanf(old,"%d %s %s %d %d %d %lf",&account_number,list ->name, list ->address ,list ->address ,&list ->acc_type,&list ->age,&list ->phone)!=EOF);
  101.    //while(fscanf(old,"%s %s %s %d %d %d %lf",temp -> name, list ->address ,temp ->address ,& temp ->acc_no,&temp ->acc_type,&temp ->age,&temp ->phone)!=EOF)
  102.    {
  103.         if(account_no == account_number)
  104.         {
  105.             test = 1;
  106.             printf("Which info do you want to change?\n");
  107.             printf("1.Address\n");
  108.             printf("2.Phone\n");
  109.             printf("3.Name\n");
  110.             printf("Enter your chose: ");
  111.             scanf("%d",&chose);
  112.             if(chose == 1)
  113.             {
  114.                 scanf(" %[^\n]s",list ->address);
  115.             }
  116.             else if(chose == 2)
  117.             {
  118.                 scanf("%lf",&list -> phone);
  119.             }
  120.             else
  121.             {
  122.                 scanf(" %[^\n]s",list ->name);
  123.             }
  124.             fprintf(new,"%d %s %s %s %d %d %lf",account_number,list -> name,list -> address,list -> citizenship,list -> age, list -> acc_type,list -> phone);
  125.             printf("Chenge saved!\n");
  126.         }
  127.       /*  else
  128.         {
  129.             list = list -> next;
  130.         }*/
  131.     }
  132.     fclose(old);
  133.     fclose(new);
  134.     remove("riyad.dat");
  135.     rename("riyadnew.dat","riyad.dat");
  136.  
  137.     system("cls");
  138.     menu();
  139. }
  140.  
  141. void menu()
  142. {
  143.     int chose;
  144.     printf("Enter your chose\n");
  145.     printf("1.Create new account.\n 2.Edit account.\n 3.tranjiction.\n 4.Check the details of an exiting account.\n 5.Remove exinting account.\n 6.Vew customar list\n 7.Exit.\n");
  146.     scanf("%d",&chose);
  147.     switch(chose)
  148.     {
  149.         case 1:new_acc();
  150.         break;
  151.         case 2:edit_acc();
  152.         break;
  153.     }
  154.  
  155. }
  156.  
  157. int main()
  158. {
  159.     int pass;
  160.     printf("Welcome To Our project\n");
  161.     printf("Enter your password: ");
  162.     scanf("%d",&pass);
  163.     system("cls");
  164.     if(pass==1)
  165.     {
  166.         menu();
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement