Guest User

Untitled

a guest
Oct 12th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<malloc.h>
  4. #include<string.h>
  5. struct emp *addemp(struct emp*,char q[20],char desi[20],int,float);
  6. void display(struct emp*);
  7. struct emp
  8. {
  9. char name[20];
  10. char desi[20];
  11. int accno;
  12. float bal;
  13. struct emp *ptr;
  14. };
  15. int main()
  16. {
  17. int i,accountno,size=5;
  18. char name[20],desi[20];
  19. float balance;
  20. struct emp *head;
  21. head=NULL;
  22. for(i=0;i<=size;i++)
  23. {
  24. printf("enter the name :\n",i);
  25. scanf("%s",name);
  26. printf("enter the designation :\n",i);
  27. scanf("%s",desi);
  28. printf("enter the account no: \n");
  29. scanf("%d",&accountno);
  30. printf("Enter the balance: \n");
  31. scanf("%f",&balance);
  32. head=addemp(head,name,desi,accountno,balance);
  33. }
  34. display(head);
  35. }
  36. struct emp *addemp(struct emp *head,char n[20],char desi[20],int a,float b)
  37. {
  38. struct emp *newnode;
  39. newnode=(struct emp *)malloc(sizeof(struct emp));
  40. strcpy(newnode->name,n);
  41. strcpy(newnode->desi,desi);
  42. newnode->accno=a;
  43. newnode->bal=b;
  44. if(head==NULL)
  45. {
  46. newnode->ptr=NULL;
  47. return newnode;
  48. }
  49. else
  50. {
  51. newnode->ptr=head;
  52. return newnode;
  53. }
  54. }
  55. void display(struct emp *head)
  56. {
  57. while(head!=NULL)
  58. {
  59. printf("name=%s\t destination=%s accno=%d\t bal=%f \n",head->name,head->desi,head->accno,head->bal);
  60. head=head->ptr;
  61. }
  62. }
Add Comment
Please, Sign In to add comment