Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct element
- {
- char client[20];
- struct element *next;
- } nod;
- nod *adaugaClient(nod *prim, char *client)
- {
- nod *nou = (nod *)malloc(sizeof(nod));
- strcpy(nou->client, client);
- nou->next = NULL;
- if (prim == NULL)
- return nou;
- nod *q = (nod *)malloc(sizeof(nod));
- for (q = prim; q->next != NULL; q = q->next);
- q->next = nou;
- return prim;
- }
- void arataclienti(nod *prim)
- {
- nod *q = (nod *)malloc(sizeof(nod));
- for (q = prim; q!= NULL; q = q->next)
- printf("%s ", q->client);
- }
- nod *retragerecerere(nod *prim,char *client)
- { nod *aux=(nod *)malloc(sizeof(nod));
- nod *nou = (nod *)malloc(sizeof(nod));
- nou = prim;
- while(nou->next->client!=client)
- if(nou->next==NULL)
- return prim;
- aux=nou->next;
- nou->next=nou->next->next;
- if(aux)
- free(aux);
- return nou;
- }
- nod *stergeclient(nod *prim)
- {
- nod *nou = (nod *)malloc(sizeof(nod));
- nou = prim->next;
- if(prim)
- free(prim);
- return nou;
- }
- int aux=0;
- int main()
- {
- nod *prim = NULL;
- char o,nume[20];
- int val;
- while(aux==0)
- {
- printf("\n");
- printf("a : Adaugare client \n");
- printf("s : Stergere client \n");
- printf("l : Listare clienti \n");
- printf("r : Retrage client \n");
- printf("t : Termina programul \n");
- printf("\nOptiunea: ");
- while(isspace(o=getchar()) );
- printf("\n");
- if (!isspace(o))
- switch (tolower(o))
- {
- case 'a': { printf("Nume client: ");
- scanf("%s", &nume);
- prim = adaugaClient(prim,nume);
- break;}
- case 's':{
- prim = stergeclient(prim);
- break;}
- case 'l':{ puts("\nClientii sunt:");
- arataclienti(prim);
- break;}
- case 'r':{
- scanf("%s", &nume);
- prim = retragerecerere(prim,nume);
- break;}
- case 't':
- aux=1;
- default:
- printf("Eroare : Comanda inexistenta\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement