fopen()和fprintf()函数很好但文件是空的 -

时间:2016-03-22 00:35:49

标签: c multithreading printf fopen fclose

我有这样一个问题: fprintf function not working but it returns positive number

我使用fopen("name","w"); main.c 中创建文件 并使用fopen("name","a")fprintf; sec.c 中写信给它。

但我使用fclose()& fopen(),每次我想写信给它。 fopen()不是NULLfprintf()返回正数。 运行时间后文件为空..

想法?

感谢。

编辑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);
                }
            }

和文件创建 -

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;

}

0 个答案:

没有答案