On Fri, Jul 18, 2008 at 5:15 AM, Kiran Divakaran
<[EMAIL PROTECTED]> wrote:
> The function failing is attached. The #if 0 code if uncommented then leads to
> a working version if retained throws a core dump.
> Also if the following lines are anywhere added in the function once ( either
> beginning / middle or end ) then the core is not dumped.
>
> {FILE *fp=fopen("xdKm.txt","a+");
> fprintf(fp,"%s \n","I am Here2");
> fclose(fp);}
Bad practice to use fopen and then neglect to verify that the file was
actually opened. If the call to fopen fails, then fp will be NULL and
your subsequent call to fprintf will fail. You should do
FILE *fp;
if((fp = fopen("xdKm.txt", "a+") == NULL) {
/* handle error, print msg, exit function, etc */
}
fprintf(...);
close fp;
I also question the way you are using fprintf -- why use a format
string if you are using a string const? Why not just do
fprintf(fp, "I am Here2\n");
or even
fputs(fp, "I am Here2\n");
-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi