RE: [Dev-C++] Some help with ported C ansi code
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-07-25 01:33:41
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Roberto Ricardi
> Sent: Wednesday, July 24, 2002 6:59 AM
> To: dev...@li...
> Subject: [Dev-C++] Some help with ported C ansi code
>
>
> Hi all,
>
> I ported all my code from DJGPP to Dev-C++ in ansi C format. The
> compilation is ok now.
> But when I run it the program crash near at the end.
>
> I use some like 8 files to read or write in a form
> FILE *fp1 ...*fp8;
>
> fp1 = fopen(archme,"r");
> fp2 = fopen(archme,"w");
> and so on
You must check for successful opening. If there is a failure fopen()
returns NULL.
So you should do:
fp1=fopen(archme, "r");
if(fp1==NULL)
{
fprintf(stderr, "Men the lifeboats. Women and children first!\n");
return EXIT_FAILURE;
}
etc.
>
> fprintf (fp2,"format", variables here );
> ........
> .........
> etc.
>
> Finally fclose to end it. So ...
>
> The file *fp4 looks with 0 bytes ever.
>
> the other files are not empty but look not completed at all.
>
> I see the crash zone about fclose files sentences.
> Need I do some like a flush before close the files ?
No you do not need to fflush(). Simply you probably fclose(NULL); (see
above). Or some other mistake in code you did not mention.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|