Guest User

Untitled

a guest
Nov 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<ctype.h>
  4. FILE *fptr;
  5. void writedetails();
  6. void readdetails();
  7. void main(){
  8. int ch;
  9. do{
  10. printf("Enter 1 to write details of clients.");
  11. printf("nEnter 2 to read details of clients with 0 balance.");
  12. printf("nEnter 3 to exit.");
  13. printf("nEnter your choice:");
  14. scanf("%d",&ch);
  15. if(ch==1){
  16. writedetails();
  17. }
  18. else if(ch==2){
  19. readdetails();
  20. }
  21. else if(ch==3){
  22. exit(0);
  23. }
  24. }while(ch!=3);
  25. getch();
  26. }
  27. void writedetails(){
  28. char name[20];
  29. int ac_no;
  30. int bal;
  31. char ch2 = 'y';
  32. fptr = fopen("CLIENTS.DAT","w");
  33. while(toupper(ch2) == 'Y'){
  34. printf("nEnter the details of client:");
  35. printf("nAccount no: ");
  36. scanf("%d",&ac_no);
  37. printf("Name: ");
  38. scanf("%s",&name);
  39. printf("Balance: ");
  40. scanf("%d",&bal);
  41. fprintf(fptr,"%d %s %d",ac_no,name,bal);
  42. printf("Press 'Y' to continue or any other key to stop.n");
  43. ch2 = getche();
  44. }
  45. fclose(fptr);
  46. }
  47. void readdetails(){
  48. char name[20];
  49. int ac_no;
  50. int bal;
  51. printf("nDetails of all clients with 0 balance:n");
  52. printf("nA/C no--------Name-------Balance");
  53. printf("n--------------------------------n");
  54. fptr = fopen("CLIENTS.DAT","r");
  55. while((fscanf(fptr,"%d%s%d",&ac_no,&name,&bal))>0){
  56. if(bal==0){
  57. printf("n %6d t %-20s %6d",ac_no,name,bal);
  58. }
  59. printf("nn");
  60. }
  61. fclose(fptr);
  62. }
Add Comment
Please, Sign In to add comment