Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<ctype.h>
- FILE *fptr;
- void writedetails();
- void readdetails();
- void main(){
- int ch;
- do{
- printf("Enter 1 to write details of clients.");
- printf("nEnter 2 to read details of clients with 0 balance.");
- printf("nEnter 3 to exit.");
- printf("nEnter your choice:");
- scanf("%d",&ch);
- if(ch==1){
- writedetails();
- }
- else if(ch==2){
- readdetails();
- }
- else if(ch==3){
- exit(0);
- }
- }while(ch!=3);
- getch();
- }
- void writedetails(){
- char name[20];
- int ac_no;
- int bal;
- char ch2 = 'y';
- fptr = fopen("CLIENTS.DAT","w");
- while(toupper(ch2) == 'Y'){
- printf("nEnter the details of client:");
- printf("nAccount no: ");
- scanf("%d",&ac_no);
- printf("Name: ");
- scanf("%s",&name);
- printf("Balance: ");
- scanf("%d",&bal);
- fprintf(fptr,"%d %s %d",ac_no,name,bal);
- printf("Press 'Y' to continue or any other key to stop.n");
- ch2 = getche();
- }
- fclose(fptr);
- }
- void readdetails(){
- char name[20];
- int ac_no;
- int bal;
- printf("nDetails of all clients with 0 balance:n");
- printf("nA/C no--------Name-------Balance");
- printf("n--------------------------------n");
- fptr = fopen("CLIENTS.DAT","r");
- while((fscanf(fptr,"%d%s%d",&ac_no,&name,&bal))>0){
- if(bal==0){
- printf("n %6d t %-20s %6d",ac_no,name,bal);
- }
- printf("nn");
- }
- fclose(fptr);
- }
Add Comment
Please, Sign In to add comment