Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include <ctype.h>
- typedef struct stud
- {
- char nume[20];
- int varsta;
- struct stud* next;
- }Lstud;
- Lstud *prim, *ultim, *p;
- Lstud *cautare(char cheie[20])
- {
- p=prim;
- while(p!=0){
- if(strcmp(p->nume,cheie)==0)
- return p;
- else
- p=p->next;
- }
- return 0;
- }
- // la final
- void addElement(char n[],int v){
- p=(Lstud*)malloc(sizeof(Lstud));
- strcpy(p->nume,n);
- p->varsta=v;
- p->next=0;
- if(ultim==0)
- prim=p;
- else
- ultim->next=p;
- ultim=p;
- }
- void creare(){
- FILE *f;
- int v;
- char str[30],*tk;
- const char sep[2]=",";
- f=fopen("date.txt","r");
- while(!feof(f))
- {
- fgets(str,30,f);
- tk=strtok(str,sep);
- v=atoi(strtok(NULL,sep));
- addElement(tk,v);
- }
- }
- //la inceput
- void add_prim(){
- char n[20];
- int v;
- printf("\nDati elementele nodului");
- scanf("%s %d",n,&v);
- p=(Lstud*)malloc(sizeof(Lstud));
- strcpy(p->nume,n);
- p->varsta=v;
- if(prim==0)
- ultim=p;
- else
- p->next=prim;
- prim=p;
- }
- void add_cheie(){
- char n[20];
- int v;
- Lstud *temp,*temp2,*q;
- p=prim;
- printf("\nDati cheia");
- scanf("%s",n);
- temp=cautare(n);
- if(temp==0)
- {
- printf("Elementul nu a fost gasit");
- return ;
- }
- else {
- while (p->nume != temp->nume)
- {
- q=p;
- p=p->next;
- }
- printf("\nDati elementele nodului");
- scanf("%s %d",n,&v);
- temp2=(Lstud*)malloc(sizeof(Lstud));
- strcpy(temp2->nume,n);
- temp2->varsta=v;
- temp2->next=temp;
- q->next=temp2;
- }
- }
- int main()
- {
- prim=0;
- ultim=0;
- int opt = -1;
- while(opt!=4)
- {
- printf("\n 1.Citire_date \n 2.Salvare \n 3.Afisare \n \n 4.Exit");
- printf("\nDati optiunea:\n");
- scanf("%d",&opt);
- switch(opt)
- {
- case 1:creare(); break;
- case 2:add_prim();break;
- case 3: add_cheie();break;
- case 4: return 0;
- default: printf("\n Optiune gresita"); break;
- }}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement