Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct stats
- {
- int account;
- float balance;
- struct stats *next;
- };
- void fill_structure(struct stats *s);
- void delete(int no);
- struct stats *create(void);
- int main()
- {
- struct stats *first;
- struct stats *current;
- struct stats *nou;
- int x = 3;
- int no;
- first = create();
- current = first;
- for(x=0;x<3;x++)
- {
- if(x==0)
- {
- first = create();
- current = first;
- }
- else
- {
- nou = create();
- current->next = nou;
- current = nou;
- }
- fill_structure(current);
- }
- current->next = NULL;
- current = first;
- while(current)
- {
- printf("Account %05d:\t$%.2f\n", current->account, current->balance);
- current = current->next;
- }
- printf ("\n choose an account to delete: ");
- scanf("%d",&no);
- delete(no);
- current=first;
- while(current)
- {
- printf("Account %05d:\t$%.2f\n", current->account, current->balance);
- current = current->next;
- }
- return(0);
- }
- void fill_structure(struct stats *s)
- {
- printf("Account number: ");
- scanf("%d",&s->account);
- printf("Balance: $");
- scanf("%f",&s->balance);
- s->next = NULL;
- }
- struct stats *create(void)
- {
- struct stats *newone;
- newone = (struct stats *)malloc(sizeof(struct stats));
- if( newone == NULL)
- {
- puts("Memory error");
- exit(1);
- }
- return(newone);
- }
- void delete (int no)
- {
- struct stats *a;
- struct stats *first;
- int *c;
- c=&no;
- if(c==1)
- {
- a=first;
- first=first->next;
- free (a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement