#include <conio.h> /* for clrscr() function */
#include <stdio.h> 
#include <stdlib.h> 
struct student 
 { 
 char name[10]; 
 unsigned int age; 
 unsigned int weight; 
 struct student *next; 
 }; 

struct student *addstudent(); 
void viewstudents(); 

struct student *headptr; 
struct student *current; 

void main() 
{ 
int choice; 
printf("\n\nFirst Students\n"); 
headptr = addstudent(); 
current = headptr; 
do 
 { 
 clrscr(); /* Clears the screen */ 
 printf("\n\n\n\n\n\n                     Menu"); 
 printf("\n                     -----------------"); 
 printf("\n                     1 - Add Student"); 
 printf("\n                     2 - View Student List"); 
 printf("\n                     3 - Quit Program\n"); 
 scanf("%d", &choice); 
 if (choice == 1) 
  { 
  current->next = addstudent(); 
  current = current->next; 
  } 
 if (choice == 2) 
  viewstudents(); 
 }while (choice != 3) ; 
} 
  

struct student *addstudent() 
{ 
struct student *ptr; 
if ((ptr = (struct student *)malloc(sizeof(struct student))) == NULL) 
 {printf("\nMemory Error"); 
 exit(1); 
 } 
ptr->next = NULL; 
printf("\nWhat is the student's name?"); 
scanf("%s", &ptr->name); 
printf("\nWhat is the student's age?"); 
scanf("%d", &ptr->age); 
printf("\nWhat does the student weigh?"); 
scanf("%d", &ptr->weight); 
return ptr; 
}; 
  

void viewstudents() 
{ 
struct student *currentptr; 
currentptr = headptr; 
clrscr(); 
printf("                   Printout of students\n"); 
while (currentptr != NULL) 
 { 
 printf("%s is %d years old and weighs %d\n",currentptr->name, currentptr->age, currentptr->weight); 
 currentptr = currentptr->next; 
 }; 
printf("End of List\n"); 
printf("Press a key to continue"); 
getch(); /* simply waits for you to press a key  This function is in conio.h*/ 
};

