C:无法将fprintf打印到输出文件

时间:2016-06-02 04:15:30

标签: c printf fopen

我试图将矩阵打印到csv中。 arg [2]在这是文件名,我可以验证它是否正常工作,因为它将生成文件,但不会填充它。我关闭文件并尝试刷新它但它不起作用。

// Open the output/second file and write the contents of truncated DCT matrix into it
outputfp = fopen(argv[2], "w");

if (outputfp == NULL) {

fprintf(stderr, "Can't open output file %s!\n", argv[2]);
exit(1);
                      }
double hold = 0;
printf("test\n");

for (i = 0, i < idx; i++;) {
    for (j = 0, j < ARRAY_WIDTH; j++;) {

    hold = test_write[i][j];

            fprintf(outputfp, "%.61f", hold);
                if (j != ARRAY_WIDTH) {

                    fprintf(outputfp, ",");
                }
                else {
                    //continue;
                }
                fflush(outputfp);
    }
}

fclose (outputfp);
return 0;
}

1 个答案:

答案 0 :(得分:4)

这个周期

 for (j = 0, j < ARRAY_WIDTH; j++;) {

从不迭代。

错误放置,;会使j++成为迭代条件。从第一次迭代j++求值到0之前,永远不会进入循环。显然,你打算写

 for (j = 0; j < ARRAY_WIDTH; j++) {
相关问题