HI
i want find record in file and null it . i find it and set file pointer
with --fsetpos--befor i use --fwrite-- . all thing id correct
but record not change and fwrite write record at end of file
i use ftell() and fseek() but i get again this problem
see
16----------------pos befor write
56---------------pos after write
at end of this post.messages are for trace and not part of my program.
what is problem?
thanks
fpos_t pos;
while(!feof(aDat)){//while
if(0 != fgetpos(aDat,&pos)){
perror("Error with fsetpos function");
exit(EXIT_FAILURE);
}
long pos1 ;//++++++++++++++++++
pos1 = ftell (aDat);//+++++++++++++++++
cout<<pos1<<"---------------pos befor read\n" ;
getch();
fread(&a , sizeof(class amanat) , 1 , aDat) ;
//fflush(aDat);
pos1 = ftell (aDat);//+++++++++++++
cout<<pos1<<"----------------pos after read\n\n" ;
cout<<a.member_id<<"---->number_id in file*book_isbn
in file---->"<<a.book_isbn<<endl;
cout<<member_id<<"---->number_id THAT you entered*book_isbn
THAT you entered---->"<<book_isbn<<endl<<endl;
getch();
if (a.member_id == member_id && a.book_isbn==book_isbn ){
a.member_id =NULL;
a.book_isbn =NULL;
if(0 != fsetpos(aDat,&pos)){
perror("Error with fsetpos function");
exit(EXIT_FAILURE);
}
pos1 = ftell (aDat);//++++++++++++++
cout<<pos1<<"----------------pos befor write\n" ;
fwrite(&a , sizeof(class amanat) , 1 , aDat) ;
pos1 = ftell (aDat);
cout<<pos1<<"---------------pos after write\n" ;
cout<<"\nbacking of book autherised ...\n";
cout << "\n\n press key to main menu \n\n" ;
getch();
clrscr();
return_menu();
goto out ;
}
}//while
-------------------------
this is sample result
Enter Member Id : 2
Enter isbn Of book : 3
0---------------pos befor read
8---------------pos after read
1---->number_id in file*book_isbn in file---->1
2---->number_id THAT you entered*book_isbn THAT you entered---->3
8---------------pos befor read
16---------------pos after read
1---->number_id in file*book_isbn in file---->2
2---->number_id THAT you entered*book_isbn THAT you entered---->3
16---------------pos befor read
24---------------pos after read
2---->number_id in file*book_isbn in file---->3
2---->number_id THAT you entered*book_isbn THAT you entered---->3
16----------------pos befor write
56---------------pos after write
backing of book autherised ...