Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<conio.h>
- typedef enum{
- milioane,miliarde
- };
- typedef struct{
- int loc, suma;
- char nume[20],sport[20];
- }Sportiv;
- Sportiv s[20];
- int n;
- void citire()
- {
- FILE *f;
- f=fopen("sportivi.txt", "rt");
- if(f==NULL)
- {
- printf("fisierul nu se poate deschide!");
- }
- else
- {
- while(!feof(f))
- {
- fscanf(f, "%d %s %s %d", &s[n].loc, s[n].nume, s[n].sport, &s[n].suma);
- }
- }
- }
- void afisare()
- {
- int i;
- for(i=0;i<n;i++)
- printf( "%d %s %s %d\n", s[i].loc, s[i].nume, s[i].sport, s[i].suma);
- }
- int Linary(char nume[20])
- {
- int i;
- for(i=0;i<n;i++)
- if(strcmp(s[i].nume, nume)==0)
- return i;
- return i;
- }
- void Shellsort()
- {
- int h[3]={ 3,2,1 };
- int i, j, w, k;
- Sportiv aux;
- for(w=0; w<3; w++)
- {
- k=h[w];
- for(i=k; i<n; i++)
- {
- aux= s[i];
- j=i-k;
- if(j>=0 && strcmp(s[j].nume, aux.nume)>0)
- {
- s[j+k]=s[j];
- j-=k;
- }
- s[j+k]=aux;
- }
- }
- }
- int main()
- {
- int i, opt;
- char nume[20];
- do
- {
- printf("~~~~~Meniu~~~~~\n");
- printf("1.Citire informatii.\n");
- printf("2.Afisare informaii.\n");
- printf("3.Cautare informatii.\n");
- printf("4.Sortare informatii.\n");
- printf("Introduceti o optiune: \n");
- scanf("%d", &opt);
- switch (opt)
- {
- case 1:
- citire();
- break;
- case 2:
- afisare();
- break;
- case 3:
- printf("introduceti numele cautat: ");
- scanf("%s", nume);
- i=Linary(nume);
- if (i != n)
- printf("%d %s %s %d", s[i].loc, s[i].nume, s[i].sport, s[i].suma);
- else
- printf("Nu exista");
- break;
- case 4:
- Shellsort();
- afisare();
- break;
- default:
- printf("optiunea introdusa nu exista!\n");
- break;
- }
- }while(opt !=4);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment