Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct employeeData
  6.  {
  7.  
  8.         int EMP_ID;
  9.         char name[20];
  10.         int dept;
  11.         int rank;
  12.         double salary;
  13.         struct employeeData *next;
  14.  
  15. } LLemployeeData;
  16. LLemployeeData *myListHEAD;
  17.  
  18.  
  19. void initalizeList(FILE *inputFile);
  20. void print();
  21.  
  22. int main ()
  23. {
  24.     FILE *inputFile = fopen("empinfooo.txt", "r");
  25.     if (!inputFile) return 1;
  26.  
  27.     myListHEAD=NULL;
  28.  
  29.  
  30.  
  31.     initalizeList(inputFile);
  32.  
  33.  
  34.     printf("%d\n", myListHEAD->EMP_ID);
  35.     printf("%s\n", myListHEAD->name);
  36.     printf("%d\n", myListHEAD->dept);
  37.     printf("%d\n", myListHEAD->rank);
  38.     printf("%.0lf\n", myListHEAD->salary);
  39.  
  40.     print();
  41.  
  42.  
  43.     return 0;
  44.  
  45. }
  46.  
  47. void initalizeList(FILE *inputFile)
  48. {
  49.     int EM, dep, ran;
  50.     char nam[20];
  51.     double salar;
  52.     int i = 0;
  53.     LLemployeeData *newNode;
  54.     newNode = (LLemployeeData *)malloc(sizeof(LLemployeeData));
  55.     LLemployeeData *temptr;
  56.     temptr = (LLemployeeData *)malloc(sizeof(LLemployeeData));
  57.  
  58.     while (i!=2)
  59.     {
  60.  
  61.  
  62.  
  63.         fscanf(inputFile, "%d %s %d %d %lf", &EM, nam, &dep, &ran, &salar);
  64.  
  65.         newNode->EMP_ID = EM;
  66.         strcpy(newNode->name, nam);
  67.         newNode->dept = dep;
  68.         newNode->rank = ran;
  69.         newNode->salary = salar;
  70.         newNode->next=NULL;
  71.  
  72.         if(myListHEAD == NULL)
  73.             myListHEAD = newNode;
  74.         else
  75.         {
  76.             temptr = myListHEAD;
  77.             while (temptr->next != NULL)
  78.                 temptr = temptr->next;
  79.             temptr->next = newNode;
  80.         }
  81.         i++;
  82.  
  83.     }
  84.     // myListHEAD = newNode;
  85.  
  86.   /*  LLemployeeData *temptr;
  87.     temptr = myListHEAD;
  88.     while (temptr->next !=NULL)
  89.         temptr = temptr -> next;
  90.  
  91.   */
  92.  
  93.     return;
  94. }
  95.  
  96. void print()
  97. {
  98.     int i=0;
  99.     LLemployeeData *temptr = myListHEAD;
  100.     while (i != 2)
  101.     {
  102.         printf("%d\n", temptr->EMP_ID);
  103.         printf("%s\n", temptr->name);
  104.         printf("%d\n", temptr->dept);
  105.         printf("%d\n", temptr->rank);
  106.         printf("%.0lf\n", temptr->salary);
  107.  
  108.         temptr = temptr -> next;
  109.         i++;
  110.     }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement