Advertisement
Aminpro

[ECP 1026]Sample Linked List Input and Output

Dec 1st, 2012
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 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.      
  8.     struct node{
  9.             char name[20];
  10.             float mark;
  11.             struct node *next;
  12.            
  13.     };
  14.            
  15.     struct node *addnode(char name[], float mark);
  16.        
  17.     int main(void){
  18.            
  19.             int j = 0;
  20.             char StdName[10];
  21.             float StdMarks;
  22.            
  23.             struct node *head = NULL;
  24.             struct node *curr = NULL;
  25.            
  26.             head = curr = addnode("\0",0.0);
  27.            
  28.             for(j=0; j<3; j++){
  29.            
  30.                     printf("\nEnter StdName >>");
  31.                     scanf("%s", StdName);
  32.                     printf("\nMarks for %s >>", StdName);
  33.                     scanf("%f", &StdMarks);
  34.                    
  35.                     curr->next = addnode(StdName, StdMarks);
  36.                     curr = curr->next;
  37.             }
  38.            
  39.             curr = head -> next;
  40.            
  41.             j = 0;
  42.            
  43.             printf("\nnode\tName\tMarks");
  44.            
  45.             while(curr){
  46.            
  47.                     printf("\n%d\t%s\t%5.2f", j++, curr->name, curr->mark);
  48.                     curr=curr->next;
  49.             }
  50.            
  51.     return 0;
  52.      
  53.     }
  54.      
  55.     struct node *addnode(char name[], float mark){
  56.            
  57.             struct node *temp;
  58.            
  59.             temp=(struct node*)malloc(sizeof(struct node));
  60.             strcpy(temp->name,name);
  61.             temp->mark=mark;
  62.             temp->next=NULL;
  63.      
  64.     return (temp);
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement