Hi,

I am writing a file by using fopen("xxxx.csv","a").

However, at a point when i open the same file it gives debug assertion error. The code is the following;

I checked if anything, like "helloworld",can be written, but no. The "ENTER??" part is written in the file correctly for 5 times. But in the 6th time, the error is encountered. Sometihng odd happens at the same point in the run. the code looks like:

Thanks for any help!

if(((W_hybrid+CT)*actnoofstations+toplam_inc_cost*1.4)<overallbestcost)
	{
		best_pf_scheme=fopen("best_pf_tuple.txt","a");
		int sayl_pf, sayj;
		//fprintf(tuple,"KK- N tuple list list:;");
		//fprintf(best_pf_scheme,"PF- N tuple list list:;");
		printf("problem!!!!!!!!!!!!");
		fprintf(best_pf_scheme,"ENTER??;");
	
		for(sayl_pf=0;sayl_pf<actnoofstations;sayl_pf++)
		{
			
			printf("%d_",arr_pf[sayl_pf]);
			fprintf(best_pf_scheme,"%d_",arr_pf[sayl_pf]);
			
		}
		
		fprintf(best_pf_scheme,";");
				
		//fprintf(best_pf_scheme,";Pass--list..;");
		for(sayj=0;sayj<N;sayj++)
		{
			if((task[sayj].pass==1)&&(task[sayj].dummy==0))
			{
				fprintf(best_pf_scheme,"%d ",sayj);
			}
				
		}
		
		fprintf(best_pf_scheme,";");

		
		overallbestcost=(W_hybrid+CT)*actnoofstations+toplam_inc_cost*1.4;
		printf("\nOVERALL BEST\n");
		
	}

What kind of debug assertion are you getting, can you give some details about it ?

ah sorry. i thought it is a common problem.

while the program is executed i get an error message saying:

"Debug assertion failed ...
file: fprintf.c line
line:56"

actually, the problem is that: i have an "if" condition. throughout the run, 5 times this if condition is executed. However, at the 6th time that the condition is true, fopen does not work. nothing is different from the previous ones.

all right.. i just do this in a big loop which has no fopen, no fprintf nothing:

bestpf=fopen("file.csv","a");
fprintf(bestpf,"What the! \n");
fclose(bestpf);

after 35 lines i get the same error. ://

Will suggest following things for you :
a) Mark proper close for fopen, after finishing all operation.
b) check for fopen error.
c) Check the size of arr_pf against actnoofstations.

hi,

it is odd, i know, but i changed the name of the file variable and voila! now it works.

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.