Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct employeeData
- {
- int EMP_ID;
- char name[20];
- int dept;
- int rank;
- double salary;
- struct employeeData *next;
- } LLemployeeData;
- LLemployeeData *myListHEAD;
- void initalizeList(FILE *inputFile);
- void print();
- int main ()
- {
- FILE *inputFile = fopen("empinfooo.txt", "r");
- if (!inputFile) return 1;
- myListHEAD=NULL;
- initalizeList(inputFile);
- printf("%d\n", myListHEAD->EMP_ID);
- printf("%s\n", myListHEAD->name);
- printf("%d\n", myListHEAD->dept);
- printf("%d\n", myListHEAD->rank);
- printf("%.0lf\n", myListHEAD->salary);
- print();
- return 0;
- }
- void initalizeList(FILE *inputFile)
- {
- int EM, dep, ran;
- char nam[20];
- double salar;
- int i = 0;
- LLemployeeData *newNode;
- newNode = (LLemployeeData *)malloc(sizeof(LLemployeeData));
- LLemployeeData *temptr;
- temptr = (LLemployeeData *)malloc(sizeof(LLemployeeData));
- while (i!=2)
- {
- fscanf(inputFile, "%d %s %d %d %lf", &EM, nam, &dep, &ran, &salar);
- newNode->EMP_ID = EM;
- strcpy(newNode->name, nam);
- newNode->dept = dep;
- newNode->rank = ran;
- newNode->salary = salar;
- newNode->next=NULL;
- if(myListHEAD == NULL)
- myListHEAD = newNode;
- else
- {
- temptr = myListHEAD;
- while (temptr->next != NULL)
- temptr = temptr->next;
- temptr->next = newNode;
- }
- i++;
- }
- // myListHEAD = newNode;
- /* LLemployeeData *temptr;
- temptr = myListHEAD;
- while (temptr->next !=NULL)
- temptr = temptr -> next;
- */
- return;
- }
- void print()
- {
- int i=0;
- LLemployeeData *temptr = myListHEAD;
- while (i != 2)
- {
- printf("%d\n", temptr->EMP_ID);
- printf("%s\n", temptr->name);
- printf("%d\n", temptr->dept);
- printf("%d\n", temptr->rank);
- printf("%.0lf\n", temptr->salary);
- temptr = temptr -> next;
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement