Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<windows.h>
- typedef struct data
- {
- int acc_no,age;
- char name[20];
- char address[20];
- char citizenship[20];
- int acc_type;
- double phone;
- struct data *pre;
- struct data *next;
- }data;
- data *head = NULL;
- data *list;
- void new_acc()
- {
- int chose,account_number;
- FILE *ptr;
- ptr = fopen("riyad.dat","a");
- data *N = (data*)malloc(sizeof(data));
- printf("Enter your name: ");
- scanf(" %[^\n]s",N -> name);
- printf("\nEnter your address: ");
- scanf(" %[^\n]s",N -> address);
- printf("\nEnter your citizenship: ");
- scanf(" %[^\n]s",N -> citizenship);
- printf("\nEnter your acc_no: ");
- scanf("%d",& N -> acc_no);
- printf("\nEnter your age: ");
- scanf("%d",& N -> age);
- printf("\nEnter your acc_type: ");
- scanf("%d",& N -> acc_type);
- printf("\nEnter your phone: ");
- scanf("%lf",& N -> phone);
- N -> pre = NULL;
- N -> next = NULL;
- if(list == NULL)
- {
- list = N;
- head = list;
- }
- else
- {
- list -> next = N;
- N -> pre = list;
- list = list -> next;
- }
- account_number = list -> acc_no;
- fscanf(ptr,"%d %s %s %s %d %d %lf",&account_number,list ->name, list ->address ,list ->address ,&list ->acc_type,&list ->age,&list ->phone);
- fprintf(ptr,"%d %s %s %s %d %d %lf",account_number,list -> name,list -> address,list -> citizenship,list -> age, list -> acc_type,list -> phone);
- fclose(ptr);
- printf("Account create successfully!");
- add_invalid:
- printf("Enter 1 for goto menu 0 for exit");
- scanf("%d",&chose);
- if(chose == 1)
- {
- menu();
- }
- else if(chose == 0)
- {
- printf("Thank you for use our project");
- }
- else
- {
- printf("Invalid input!");
- goto add_invalid;
- }
- }
- void edit_acc()
- {
- data *temp;
- int account_number,chose,test = 0,account_no;
- printf("Enter the account number whose info you want to change: ");
- scanf("%d",&account_no);
- FILE *old;
- FILE *new;
- old = fopen("riyad.dat","r");
- new = fopen("riyadnew.dat","w");
- list = head;
- /* while(list != NULL)
- {
- if(list -> acc_no == account_no)
- {
- temp = list;
- }
- list = list -> next;
- }*/
- 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);
- //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)
- {
- if(account_no == account_number)
- {
- test = 1;
- printf("Which info do you want to change?\n");
- printf("1.Address\n");
- printf("2.Phone\n");
- printf("3.Name\n");
- printf("Enter your chose: ");
- scanf("%d",&chose);
- if(chose == 1)
- {
- scanf(" %[^\n]s",list ->address);
- }
- else if(chose == 2)
- {
- scanf("%lf",&list -> phone);
- }
- else
- {
- scanf(" %[^\n]s",list ->name);
- }
- fprintf(new,"%d %s %s %s %d %d %lf",account_number,list -> name,list -> address,list -> citizenship,list -> age, list -> acc_type,list -> phone);
- printf("Chenge saved!\n");
- }
- /* else
- {
- list = list -> next;
- }*/
- }
- fclose(old);
- fclose(new);
- remove("riyad.dat");
- rename("riyadnew.dat","riyad.dat");
- system("cls");
- menu();
- }
- void menu()
- {
- int chose;
- printf("Enter your chose\n");
- 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");
- scanf("%d",&chose);
- switch(chose)
- {
- case 1:new_acc();
- break;
- case 2:edit_acc();
- break;
- }
- }
- int main()
- {
- int pass;
- printf("Welcome To Our project\n");
- printf("Enter your password: ");
- scanf("%d",&pass);
- system("cls");
- if(pass==1)
- {
- menu();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement