hii everyone1..

how can i update a text file i,e only one particular record in a file i'm using openGL with vc++ ... my sample code to write into a text file when a store button is clicked is over here..after every 8sec i have to update only x_quad and y_quad how can that be done..is ther any one who can help me out??

case STORE_BUTTON:
		fptr=fopen ("target.txt", "w");
		fclose(fptr);

		fptr=fopen("target.txt","a+");
		if(radiogroup_item_id==0)
			strng="incomming";
		else if(radiogroup_item_id==1)
			strng="outgoing";
		compute(az,sr,er,strng);
		if(no>=1)
		{
			no=no-1;
			if(tid <= 10)
			{
				
				fprintf(fptr, "Target id=%d\n", tid);
				fprintf(fptr, "%s\n", strng);
				fprintf(fptr, "speed=%f\n", speed);
				fprintf(fptr, "Azimuth=%d\n", az);
				fprintf(fptr, "Heading=%d\n", hh);
				fprintf(fptr, "Start range=%d\n", sr);
				fprintf(fptr, "End Range=%d\n",er);
			fprintf(fptr, "Point: %f, %f\n\n", X_quad,y_quad);
			}
			else if(no==0 || tid>10)
				fclose(fptr);			
		}


		tid++;
		break;

>>how can i update a text file i,e only one particular record in a file

The only way to do that is to completly rewrite the text file, making whatever changes you want while doing that.

commented: Yes +20

>>I thick you can use fseek.
fseek() is intended for binary fines, not text files. Its pretty much useless for text files.

Disclaimer: I have not used fseek personally on text files

C++ reference says that

When using fseek on text files with offset values other than zero or values retrieved with ftell, bear in mind that on some platforms some format transformations occur with text files which can lead to unexpected repositioning.

Ancient Dragon, if ashwini uses fseek with offset value 0, will he still get an error ?

He won't get an error, it just don't do anything. Why use offset of 0 except go move the file pointer to either the beginning or end of the file????

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.