Advertisement
Aminpro

[ECP1026]Tutorial 4 Question 2

Nov 28th, 2012
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. //https://www.facebook.com/AminproPastebin
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. struct Exam{
  8.     float marks;
  9.     char grade;
  10.     char code[20];
  11.     struct Exam *next;
  12. };
  13.  
  14. struct Exam * InsertNode(float x,char y,char z[]);
  15.  
  16. int main(){
  17.     struct Exam *head=NULL;
  18.     struct Exam *curr=NULL;
  19.    
  20.     head = curr = InsertNode(0.0,'\0',"\0");
  21.    
  22.     int i;
  23.        
  24.     curr->next = InsertNode(72.0,'B',"ECP1016");
  25.     curr=curr->next;
  26.     curr->next = InsertNode(85.0,'A',"ECP1026");
  27.     curr=curr->next;
  28.     curr->next = InsertNode(55.0,'C',"ECP1036");
  29.     curr=curr->next;
  30.    
  31.     curr=head;
  32.     curr=curr->next;
  33.     while(curr){
  34.         printf("%.2f %c %s\n",curr->marks,curr->grade,curr->code);
  35.         curr=curr->next;
  36.     }
  37.         return(0);
  38. }
  39.  
  40.  
  41.  
  42.  
  43. struct Exam * InsertNode(float x,char y, char z[]){
  44.    
  45.     struct Exam *temp;
  46.    
  47.     temp=(struct Exam *)malloc(sizeof(struct Exam));
  48.     temp->marks=x;
  49.     temp->grade=y;
  50.     strcpy(temp->code,z);
  51.     temp->next=NULL;
  52.     return(temp);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement