radu.nuconteaza 0 Newbie Poster
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
 struct exchange_rate

 {
     char name[50];
     float rate;
 };


int main()
{struct exchange_rate x[50],adaus,caut[20],aranj;
      int i,n,q,k,z,d; float aux,max;
      char w; int lungime;
  FILE *f1;
      //afisam meniul
   m0: system("cls");
      printf("\n\t\t***MENIU***\n\n");
      printf("\t1: Filling database.\n");
      printf("\t2: Reading the database file\n");
      printf("\t3: Introducing a new registration\n");
      printf ("\t4: Cautarea cursului dupa denumirea valutei\n");
      printf("\t5: Arrange in ascending order\n");
      printf("\t6: Overwrite data\t");
      scanf("%d",&q);
           switch(q)
       {
           case 1:goto m1;
           case 2:goto m2;
           case 3: goto m3;
           case 4: goto m4;
           case 5: goto m5;
           case 6: goto m6;
           default:goto m0;
       }
       //Filling database
m1:
    printf("Number of currency: ");
    scanf("%d",&n);
     for(i=0; i<n; i++)
     {printf("Name of currency %d: ",i+1);
     scanf("%s",x[i].name);

     scanf("%f",&aux);
      x[i].rate=aux;}

     f1=fopen("baza.txt","w");
     for(i=0; i<n; i++)
     {fwrite(&x[i],sizeof(x[i]),1,f1);}
     fclose(f1);
     printf("Baza de date a fost completata in fisierul \"baza.txt\"\n");
     printf("Pentru iesire tastati Enter");
     getch();
     goto m0;

//Reading the database file
m2: system("cls");
     printf("\n\n\n\t ***** Baza initiala este *****\n\n");
     printf("\t--------------------------------\n");
     printf("\t|  Numele Valutei| Cursul Valutei\n");
     f1=fopen("baza.txt","r");
     while(fread(&x[i],sizeof(x[i]),1,f1)==1)
     {printf("\t%12s    |%10.3f\n",x[i].name,x[i].rate);i++;}
         fclose(f1); n=i;
      printf("Pentru iesire tastati Enter");
      getch();
      goto m0;

//adaugarea
m3: system("cls");
    printf("Doriti sa mai adaugati ceva?");
    w=getch();
    if ((w=='N')||(w=='n')){
        goto m0;}
    if ((w=='Y')||( w=='y')){
        printf("\nDati numele valutei");
        scanf("%s",adaus.name);
        printf("\nDati cursul valutei");
        scanf("%f",&adaus.rate);
        f1=fopen("baza.txt","a");
        fwrite(&adaus,sizeof(adaus),1,f1);
        fclose(f1);
        printf("\n\nInscrierea a avut loc cu succes");
        printf("\nPentru iesire tastati Enter");
        getch();
        goto m0;
} //Cautarea unei valute
m4: system("cls");
    f1=fopen("baza.txt","r");
    while(fread(&x[i],sizeof(x[i]),1,f1)==1)
        {i++;};
    n=i;
    fclose(f1);
    printf("\nIntroduceti valuta care o cautati: ");
    scanf("%s",caut);
    printf("\n\n\n\t ***** Rezultatul cautarii *****\n\n");
    printf("\t|  Numele Valutei| Cursul Valutei\n");
 k=0;
     for (i=0; i<n; i++)
     {if(strcmp(x[i].name,caut)==0)
         {k++;
          printf("\t%12s    |%10.3f\n",x[i].name,x[i].rate);}}
if (k==0)
    system("cls");
    printf("\nNU exista asa nume");

printf("\nPentru iesire tastati Enter\n");
        getch();
        goto m0;

//ORDONAREA
m5:
   f1=fopen("baza.txt","r"); i=0;
   while(fread(&x[i],sizeof(x[i]),1,f1)==1)
        {i++;};
    n=i;
    fclose(f1);
   for (i=0; i<n; i++) {
     max=x[i].rate;
     z=i;
    for (d=i; d<n;d++){
        if(max<x[d].rate)
        {
            max=x[d].rate; z=d;}}
           aranj=x[i];
           x[i]=x[z];
           x[z]=aranj;}

           system("cls");
           printf("\n\n\n\t *****Bazele aranjarii*****\n\n");
           printf("\t|  Numele Valutei| Cursul Valutei\n");
          for (i=0; i<n; i++){
          printf("\t%12s    |%10.3f\n",x[i].name,x[i].rate);}
          printf("\nPentru iesire tastati Enter\n");
        getch();
        goto m0;
m6:
    //FOR OVERWRITE

   }

SORRY for another language( i translated the main thing in english...if dun understand i'll translate whole programm ..ty a lot