Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct element
  5. {
  6. char client[20];
  7. struct element *next;
  8. } nod;
  9.  
  10. nod *adaugaClient(nod *prim, char *client)
  11. {
  12. nod *nou = (nod *)malloc(sizeof(nod));
  13. strcpy(nou->client, client);
  14. nou->next = NULL;
  15. if (prim == NULL)
  16. return nou;
  17. nod *q = (nod *)malloc(sizeof(nod));
  18. for (q = prim; q->next != NULL; q = q->next);
  19. q->next = nou;
  20. return prim;
  21. }
  22. void arataclienti(nod *prim)
  23. {
  24. nod *q = (nod *)malloc(sizeof(nod));
  25. for (q = prim; q!= NULL; q = q->next)
  26. printf("%s ", q->client);
  27. }
  28. nod *retragerecerere(nod *prim,char *client)
  29. { nod *aux=(nod *)malloc(sizeof(nod));
  30. nod *nou = (nod *)malloc(sizeof(nod));
  31. nou = prim;
  32. while(nou->next->client!=client)
  33. if(nou->next==NULL)
  34. return prim;
  35.  
  36. aux=nou->next;
  37. nou->next=nou->next->next;
  38. if(aux)
  39. free(aux);
  40. return nou;
  41. }
  42. nod *stergeclient(nod *prim)
  43. {
  44. nod *nou = (nod *)malloc(sizeof(nod));
  45. nou = prim->next;
  46. if(prim)
  47. free(prim);
  48. return nou;
  49. }
  50. int aux=0;
  51. int main()
  52. {
  53. nod *prim = NULL;
  54. char o,nume[20];
  55. int val;
  56. while(aux==0)
  57. {
  58. printf("\n");
  59. printf("a : Adaugare client \n");
  60. printf("s : Stergere client \n");
  61. printf("l : Listare clienti \n");
  62. printf("r : Retrage client \n");
  63. printf("t : Termina programul \n");
  64.  
  65. printf("\nOptiunea: ");
  66. while(isspace(o=getchar()) );
  67. printf("\n");
  68. if (!isspace(o))
  69. switch (tolower(o))
  70. {
  71.  
  72. case 'a': { printf("Nume client: ");
  73. scanf("%s", &nume);
  74. prim = adaugaClient(prim,nume);
  75. break;}
  76. case 's':{
  77. prim = stergeclient(prim);
  78. break;}
  79. case 'l':{ puts("\nClientii sunt:");
  80. arataclienti(prim);
  81. break;}
  82. case 'r':{
  83. scanf("%s", &nume);
  84. prim = retragerecerere(prim,nume);
  85.  
  86. break;}
  87. case 't':
  88. aux=1;
  89. default:
  90. printf("Eroare : Comanda inexistenta\n");
  91. }
  92. }
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement