خرید بک لینک

Vote count: 0

I am new to file write/read operations in C programming. Is there a solution to write all printf() which is on the below, to my output txt file? I could not write all the lines to my txt file.

for(i=0;i < n;i++)
        if(i!=startnode)
        {
            outputFile = fopen(myOutputFile, "w");

            printf("nCOST of %d = %d", i, cost[i]);            
            printf("nTRACE = %d", i);

            j=i;
            do
            {
                j=pred[j];
                printf(" %d", j);

            }
            while(j!=startnode);
        }

asked 3 mins ago

1 Answer

Vote count: 0

You can use fprintf(FILE * stream, const char * format, ... ) and pass the file handle to the function.

for(i=0;i < n;i++)
    if(i!=startnode)
    {
        outputFile = fopen(myOutputFile, "w");

        fprintf(outputFile,"nCOST of %d = %d", i, cost[i]);            
        fprintf(outputFile,"nTRACE = %d", i);

        j=i;
        do
        {
            j=pred[j];
            fprintf(outputFile," %d", j);

        }
        while(j!=startnode);
    }

answered 6 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 12 فروردين 1395 ساعت: 17:59

صفحه بندی