Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct person {
  5. char name[20];
  6. char surname[20];
  7. char number[8];
  8. struct person* next;
  9. };
  10. typedef struct person Person;
  11. typedef Person* Personpointer;
  12.  
  13. void addrecord();
  14. void add(Personpointer);
  15. void displayrecord();
  16. void deleterecord();
  17. void searchrecord();
  18.  
  19. Personpointer head = NULL;
  20.  
  21. void addrecord() {
  22. char tname[20];
  23. char tsurname[20];
  24. char tnumber[8];
  25. int value;
  26. Personpointer ptr;
  27.  
  28. system("cls");
  29. printf("*******Add record*******");
  30. printf("\nEnter name: ");
  31. scanf_s("%s", tname);
  32. printf("\nEnter surname: ");
  33. scanf_s("%s", tsurname);
  34. do {
  35. printf("\nEnter 8-digit telephone number: ");
  36. scanf_s("%s", tnumber);
  37. } while (strlen(tnumber) != 8);
  38.  
  39. ptr = malloc(sizeof(Person));
  40.  
  41. strcpy(ptr->name, tname);
  42. strcpy(ptr->surname, tsurname);
  43. strcpy(ptr->number, tnumber);
  44. ptr->next = NULL;
  45.  
  46. insert(ptr);
  47. }
  48.  
  49. void deleterecord() {
  50.  
  51. }
  52.  
  53. void displayrecord() {
  54. Personpointer ptr = head;
  55. int index = 1;
  56. system("cls");
  57. while (ptr != NULL)
  58. {
  59. printf("%s %s %s", ptr->name, ptr->surname, ptr->number);
  60. printf("\n\n");
  61. ptr = ptr->next;
  62.  
  63. index++;
  64. }
  65.  
  66. }
  67.  
  68. void searchrecord() {
  69.  
  70. }
  71. int main(void)
  72. {
  73. int mainmenu;
  74. do {
  75. system("cls");
  76. puts("===============================");
  77. puts("\n\tPhone Directory");
  78. puts("\n===============================");
  79.  
  80. puts("\n\n1. Add telephone record.");
  81. puts("\n2. Delete telephone record.");
  82. puts("\n3. Search telephone records.");
  83. puts("\n4. Display all records.");
  84. puts("\n5. Exit.");
  85.  
  86. puts("\n\nPlease select an option.");
  87. scanf_s("%d", &mainmenu);
  88. fflush(stdin);
  89.  
  90. switch (mainmenu)
  91. {
  92. case 1:
  93. addrecord();
  94. break;
  95. case 2:
  96. deleterecord();
  97. break;
  98. case 3:
  99. break;
  100. case 4:
  101. displayrecord();
  102. break;
  103. }
  104. } while (mainmenu != 5);
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement