#include< stdio.h> #include< stdlib.h> int main() { int hesap; char ad[30]; double bakiye; FILE*fPtr; fPtr=fopen("musteri.txt","r"); if(fPtr==NULL) printf("Dosya Bozuk!!!"); else{ printf("%-10s%-13s%s\n","hesap","isim","bakiye"); fscanf(fPtr,"%d%s%lf",&hesap,ad,&bakiye); while(!feof(fPtr)){ printf("%-10d%-13s%7.2f\n",hesap,ad,bakiye); fscanf(fPtr,"%d%s%lf",&hesap,ad,&bakiye); } fclose(fPtr); } system("pause"); return 0; }
Showing posts with label fopen. Show all posts
Showing posts with label fopen. Show all posts
Tuesday, 10 January 2012
Basic File Reading in C
Random Access File Reading in C
#includestruct musteriVerisi{ int hesapNo; char soyisim[15]; char isim[10]; double bakiye; }; int main() { FILE*cfPtr; struct musteriVerisi musteri={0,"","",0.0}; if((cfPtr=fopen("kredi.dat","r"))==NULL) printf("Dosya acilamiyor\n"); else{ printf("%-6s%-16s%-11s%10s\n","HspNo","Soyisim","Isim","Bakiye"); while(!feof(cfPtr)) { fread(&musteri,sizeof(struct musteriVerisi),1,cfPtr); if(musteri.hesapNo!=0) printf("%-6d%-16s%-11s%10.2f\n",musteri.hesapNo, musteri.soyisim,musteri.isim,musteri.bakiye); } fclose(cfPtr); } getch(); return 0; }
Subscribe to:
Posts (Atom)