Advertisement
mdnurnobihosen

datastructure14

Jun 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. ///Home Work 14 @Nurnobi shanto
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. typedef struct students
  6. {
  7.     char name[15];
  8.     char id[12];
  9.     char sec[2];
  10.     char dpt[20];
  11.     struct students *next;
  12. } std;
  13. std *head = NULL;
  14. std *temp = NULL;
  15.  
  16. void inestData()
  17. {
  18.     printf("Enter number of total student:");
  19.     int i,n;
  20.     scanf("%d",&n);
  21.     for(i=0; i<n; i++)
  22.     {
  23.         printf("\nEnter student information: #%d\n",i+1);
  24.         std *newStd;
  25.         newStd= (std*)malloc(sizeof(std));
  26.  
  27.         printf("Enter Name:");scanf("%s", &newStd-> name);
  28.         printf("Enter ID:");scanf("%s", &newStd-> id);
  29.         printf("Enter Section:");scanf("%s", &newStd-> sec);
  30.         printf("Enter Department:"); scanf("%s", &newStd-> dpt);
  31.  
  32.         newStd->next=NULL;
  33.         if(head==NULL)
  34.         {
  35.             head=newStd;
  36.         }
  37.         else
  38.         {
  39.             temp=head;
  40.             while(temp->next!=NULL)
  41.             {
  42.                 temp=temp->next;
  43.             }
  44.                temp->next=newStd;
  45.         }
  46.     }
  47. }
  48.  
  49. void printInformation()
  50. {
  51.      std *temp = head;
  52.     printf("\n---------Show Students Information:---------\n");
  53.     int c=1;
  54.     while(temp != NULL)
  55.     {
  56.         printf("\nDisplay student information: #%d\n",c++);
  57.         printf("Name: %s\n",temp-> name);
  58.         printf("ID: %s\n",temp-> id);
  59.         printf("Section: %s\n",temp-> sec);
  60.         printf("Department: %s\n",temp-> dpt);
  61.         temp= temp-> next;
  62.     }
  63.  
  64.  
  65. }
  66. int main()
  67. {
  68.     inestData();
  69.     printInformation();
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement