coding matter please help

i am trying to write and read a simple program using these codes. writing code seems to work fine,it prompts for data and after it terminates properly.but the reading code only give me the error "file could not be opened". I am using visual studio 2008 express. thank you!!

writing code

#include



int main(void)
{
int account;
char name[30];
double balance;

FILE *cptr;
if ((cptr=fopen("clients.dat","w"))==NULL){
printf("hello world");
}
else{
printf("enter the account details\n");
printf("enter EOF\n");
printf("?");
scanf("%d%s%lf",&account,name,&balance);
while(!feof(stdin))
{
fprintf(cptr,"%d%s%.2f\n",account,name,balance);
printf("?");
scanf("%d%s%lf",&account,name,&balance);
}
fclose(cptr);
}


return 0;
}

reading code

#include
#include

int main(void)
{
int account;
char name[30];
double balance;

FILE *cptr;

if (( cptr = fopen("clients.dat","r")) == NULL){
printf("file cannot be opened\n");
}
else
{
printf("%-10s%-13s%s\n","Account","Name","Balance");
fscanf(cptr,"%d%s%lf",&account,name,&balance);
while (!feof(cptr)){
printf("%-10d%-13s%7.2f",account,name,balance);
fscanf(cptr,"%d%s%lf",&account,name,&balance);
}
fclose(cptr);
}
getch();
return 0;
}

Replies

  • Deitel
    Deitel
    i am an administrator in the computer,do you think I might not have to right to write on the disk,if so is there a way to change it😔
  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    Hey, this code runs only in Turbo C and not Visual Studio. 😀 Please download Borland C for Windows and try it out... 😀

You are reading an archived discussion.

Related Posts

When exactly should we replace the bearings of vehicle wheels? How to know whether bearings are to be replaced? What exactly/How exactly ball bearings work in Cars and other vehicles?...
i m final year project please help me out in selecting some topics for my major project....
hi i want to decode a data(DAT) file of the game to see the source code of the game to fix it glitches and bug please help is there any...
hey friends, i need some new ideas related to Electrical and electronics group for my mini project i have some but we can't make them possible with this technology so...
Engineers please guide me about "discharge measurement and common errors in discharge measurement"