6 Haziran 2017 Salı

C++ Fread Kullanımı

#include < QCoreApplication >
#include< stdio.h >
struct musteriVerisi
{
    int hesap_No;
    char soyisim[30];
    char isim[50];
    double bakiye;
};
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    FILE *Ptr;
    struct musteriVerisi musteri={0,"","",0.0};
    if((Ptr=fopen("musteri.dat","r"))==NULL)
    {
        printf("Dosya Acilamadi");
    }
    else
    {
        printf("Hesap Numarasini Giriniz : \n");
        scanf("%d",&musteri.hesap_No);

       printf("%10s%15s%20s%25s\n","HesapNo","Soyad","Ad","Bakiye");

       while(!feof(Ptr))
       {
           fread(&musteri,sizeof(struct musteriVerisi),1,Ptr);
           if(musteri.hesap_No !=0)
           {
               printf("%10d%15s%20s%25lf\n",musteri.hesap_No,
                        musteri.soyisim,musteri.isim,musteri.bakiye);

           }
       }
           fclose(Ptr);
    }
    return 0;
}


Share: