daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest May 17th, 2018 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct stats
  5. {
  6.     int account;
  7.     float balance;
  8.     struct stats *next;
  9. };
  10.  
  11. void fill_structure(struct stats *s);
  12. void delete(int no);
  13. struct stats *create(void);
  14.  
  15. int main()
  16. {
  17.     struct stats *first;
  18.     struct stats *current;
  19.     struct stats *nou;
  20.     int x = 3;
  21.     int no;
  22.  
  23.     first = create();
  24.     current = first;
  25.  
  26.     for(x=0;x<3;x++)
  27.     {
  28.         if(x==0)
  29.         {
  30.  
  31.             first = create();
  32.             current = first;
  33.         }
  34.         else
  35.         {
  36.             nou = create();
  37.             current->next = nou;
  38.             current = nou;
  39.         }
  40.         fill_structure(current);
  41.     }
  42.     current->next = NULL;
  43.  
  44.     current = first;
  45.     while(current)
  46.     {
  47.         printf("Account %05d:\t$%.2f\n", current->account, current->balance);
  48.         current = current->next;
  49.     }
  50.     printf ("\n choose an account to delete: ");
  51.     scanf("%d",&no);
  52.     delete(no);
  53.    
  54.     current=first;
  55.         while(current)
  56.     {
  57.         printf("Account %05d:\t$%.2f\n", current->account, current->balance);
  58.         current = current->next;
  59.     }
  60.  
  61.     return(0);
  62. }
  63.  
  64. void fill_structure(struct stats *s)
  65. {
  66.     printf("Account number: ");
  67.     scanf("%d",&s->account);
  68.     printf("Balance: $");
  69.     scanf("%f",&s->balance);
  70.     s->next = NULL;
  71. }
  72.  
  73. struct stats *create(void)
  74. {
  75.     struct stats *newone;
  76.  
  77.     newone = (struct stats *)malloc(sizeof(struct stats));
  78.     if( newone == NULL)
  79.     {
  80.         puts("Memory error");
  81.         exit(1);
  82.     }
  83.     return(newone);
  84. }
  85.  
  86.  
  87. void delete (int no)
  88. {
  89.  
  90. struct stats *a;
  91. struct stats *first;
  92. int *c;
  93. c=&no;
  94.  
  95.  
  96. if(c==1)
  97. {
  98.     a=first;
  99.     first=first->next;
  100.     free (a);
  101. }
  102.  
  103. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top