我想在Linux下使用C程序将表写入文件。但我无法把它们一个接一个地排列。有什么可以做的吗?提前谢谢。
fprintf(fp_for_summary,"----------------------------------------n");
fprintf(fp_for_summary,"| S.No | Filenamet | Complexity Index |n");
fprintf(fp_for_summary,"----------------------------------------n");
for(i=0;i<cnt;i++)
{
fprintf(fp_for_summary,"| %d | %st | %d |n", i, filename, cmplxty);
}
fprintf(fp_for_summary,"| %6d | %32st | %6d |n", i, filename, cmplxty);
用正确的数字代替
你可以使用固定的宽度:
int width1 = 3;
int width2 = 3;
int width3 = 3;
fprintf(fp_for_summary,"----------------------------------------n");
fprintf(fp_for_summary,"| S.No | Filenamet | Complexity Index |n");
fprintf(fp_for_summary,"----------------------------------------n");
for(i=0; i<cnt; i++)
fprintf(fp_for_summary,"| %*d | %*st | %*d |n", width1, i, width2, filename, width3, cmplxty);