I have a problem like this one: fprintf function not working but it returns positive number
I create the file in main.c with fopen("name","w");
and write to it in sec.c with fopen("name","a") and fprintf;.
but I use fclose() & fopen(), each time that I want to write to it.
fopen() is not NULL and fprintf() return positive number..
After the running time the file is empty..
Ideas ?.
Thanks.
edit 1:
lbl=findlabel();/*find the label in label[].*/
        if( lbl )/*find it*/
        {
            if( ((lbl->feature.ext)==0) )/*internal label.*/
            {
                /*write in prog1.ent file & move to the next line.*/
                fpentry=fopen(entf,"a");
                setbuf(fpentry,entbuf);
                if( (fpentry) )
                {
                    printf("*****\n.entry access the file.\n*****\n");
                    count1=fprintf(fpentry," %s \n",label);
                    fflush(fpentry);
                    /*fclose(fpentry);*/
                    printf("***ENTRY: the num is:%d\nThe label is:%s.\nThe address is:%d.\n",count1,label,lbl->adess);
                }
                else/*cant open the file.*/
                {
                    fflush(fpentry);
                    fflush(stderr);
                    printf("*****\n.entry cant access the file.\n*****\n");
                    fprintf(stderr,"error: in file:%s, line:%d, ", fname, flinec);
                    fprintf(stderr,"cant open the file:%s to write.\n",entf);
                }
            }
and the file creation -
Dword secondpass(FILE *stream){
Dword lpace;
time_t t;
Dword *codearr=NULL;
srand((unsigned)time(&t));
puts("\n*****\nWelcome to second pass!.\n*****\n");
strcpy(entf,fname);
strcpy(extf,fname);
strcat(entf,".ent");
strcat(extf,".ext");
while( (fgets(line, MAXROWLEN, stream)) != NULL )
{
    fflush(stderr);
    codearr=(Dword*)calloc( ((IC-SIC)+DC) , sizeof(Dword) );
    if( ( pextf=fopen(extf,"w") ) && ( fpentry=fopen(entf,"w") ) )
    {
        fprintf(pextf,"The extern file:\n");
        fprintf(fpentry,"The entry file:\n");
        fflush(pextf);
        fflush(fpentry);
        addup();/*update all the internal addresses of labels by adding it IC.*/
        labelflag=getlabel();/*move p after the label*/
        SKIP
        lpace=getcmd();
    }
    else/*failed to create wanted files.*/
    {
        fprintf(stderr,"error: in file:%s, line:%d, ", fname, flinec);
        fprintf(stderr,"Second pass cant create files.\n");
        break;
    }
}/*end of while loop: end of reading file.*/
fclose(pextf);
fclose(fpentry);
/*rember to free all pointer & all memory!.*/
free(codearr);
return lpace;
}
 
    