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 ...

i get current pointer location before read by

pos1 = ftell (aDat);--------for trace
and 
fgetpos(aDat,&pos);---------for real getting

then after find record before writing in file i set pointer by

fsetpos(aDat,&pos);

but fwrite write at another location for example see at output:

16----------------pos befor write
56---------------pos after write

that should to be

16----------------pos befor write
20---------------pos after write

fsetpos change pointer correctly to ---> 16 but fwrite not work good .
i use another way that use fseek but get same error
what is problem
urgent
thanks

no one has idea

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.