#include <stdio.h> #include <stdlib.h> int main() { int account; char name[30];
ID: 3630007 • Letter: #
Question
#include <stdio.h>
#include <stdlib.h>
int main()
{
int account;
char name[30];
double balance;
FILE *cfPtr;
if((cfPtr = fopen("clients.dat","w")) == NULL){
printf("File could not be opened ");
}
else{
printf("Enter Account Info, Name and Balance ");
printf("Enter EOF to end input ");
printf("? ");
scanf("%d%s%lf",&account,name,&balance);
/*write to file*/
while(!feof(stdin)){
fprintf(cfPtr,"%d,%s,%.2f ", account, name, balance);
printf("? ");
scanf("%d%s%lf",&account,name,&balance);
}
fclose(cfPtr);
}
return 0;
}
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int account;
char name[30];
double balance;
FILE *cfPtr;
if((cfPtr = fopen("clients.dat","w")) == NULL){
printf("File could not be opened ");
}
else{
printf("Enter Account Info, Name and Balance ");
printf("Enter EOF to end input ");
printf(" ");
scanf("%d%s%lf",&account,name,&balance);
/*write to file*/
while(!feof(stdin)){
fprintf(cfPtr,"%d,%s,%.2f ", account, name, balance);
// here i removed 2 lines
// now give a try
}
fclose(cfPtr);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.