Advertisement
Aminpro

[ECP 1026]Another Linked list sample

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