Advertisement
Guest User

Friend name

a guest
Feb 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct Node
  4. {
  5. int x;
  6. char name[10];
  7. struct Node *ptr;
  8. }node;
  9.  
  10. node *head = NULL;
  11.  
  12. node *temp = NULL;
  13.  
  14. int main()
  15. {
  16. int i, n, j;
  17. printf("Number of friends:");
  18. scanf("%d", &n);
  19. for(i=1; i<=n; i++)
  20. {
  21. node *q = (node*)malloc(sizeof (node));
  22. printf("\nEnter Name:");
  23. scanf("%s", q -> name);
  24. printf("Enter His Phone No:");
  25. scanf("%d", &q -> x);
  26. q -> ptr = NULL;
  27. if(head == NULL)
  28. {
  29. head = q;
  30. }
  31. else
  32. {
  33. temp = head;
  34. while(temp -> ptr != NULL)
  35. {
  36. temp = temp -> ptr;
  37. }
  38.  
  39. temp -> ptr = q;
  40. }
  41. }
  42.  
  43. temp = head;
  44. printf("\nYou have %d friends in your list\n\n", n);
  45. for(j=1; temp!= NULL; j++)
  46. {
  47. printf("Friend %d:\n", j);
  48. printf("Name:%s\n", temp->name);
  49. printf("Phone No:%d\n\n", temp->x);
  50. temp = temp->ptr;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement