Advertisement
Guest User

chap chap

a guest
Dec 8th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. typedef struct node
  5. {
  6. char name[20];
  7. char phone[20];
  8. struct node *next;
  9.  
  10. } node;
  11. node *head=NULL;
  12. void insert_at_last()
  13. {
  14. node *n=(node*)malloc(sizeof(node));
  15. n->next=NULL;
  16. printf("Enter Name:");
  17. scanf(" %[^\n]",n->name);
  18. printf("Enter his Phone NO:");
  19. scanf(" %[^\n]",n->phone);
  20. if(head==NULL)
  21. {
  22. head=n;
  23. }
  24. else
  25. {
  26. node *list=head;
  27. while(list->next!=NULL)
  28. {
  29. list=list->next;
  30. }
  31. list->next=n;
  32. }
  33. return;
  34. }
  35. void display(int x)
  36. {
  37. int count=1;
  38. printf("You have %d friend in your list\n",x);
  39. node *list=head;
  40. while(list!=NULL)
  41. {
  42. printf("Friend %d:\n",count);
  43. printf("Name:%s\n",list->name);
  44. printf("Phone No:%s\n",list->phone);
  45. printf("\n");
  46. list=list->next;
  47. count++;
  48. }
  49. return;
  50. }
  51. int main()
  52. {
  53. int x;
  54. printf("Number Of friends:");
  55. scanf("%d",&x);
  56. int i;
  57. for(i=0; i<x; i++)
  58. {
  59. insert_at_last();
  60. }
  61. display(x);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement