我想格式化结果,以便进行调整
这是我到目前为止所写的内容:
void affichage(int note[][50],char nom[][50],float moy[], float moy_e[], char module[][50],int nb_etudiant, int nb_module){
int i,j;
printf("\n\t\taffichage\n\n");
printf("\t");
strcpy(module[nb_module],"Moy G");
strcpy(nom[nb_etudiant],"Moy C");
for (i=0;i<nb_module;i++){
printf("%5s ",module[i]);
}
printf(" %5s",module[nb_module]);
printf("\n");
for(i=0;i<nb_etudiant;i++){
printf("%-5s ",nom[i]);
for (j=0;j<nb_module;j++){
printf("%-7d ", note[i][j]);
}
printf(" %-7.1f\n",moy_e[i]);
}
printf("\n\n");
printf("%5s ",nom[nb_etudiant]);
for (i=0;i<nb_module;i++){
printf("%-7.1f ",moy[i]);
}
}
答案 0 :(得分:-2)
作为建议,printf返回格式化的字符串的长度。
由于您要显示学生的数据,如果我们假设您有一个有两列的表格
X chars Y chars -------|------ -------|--------- | | | ---------------------------------------- nom | prénom | note ---------------------------------------- Jane | Mari | 15 ---------------------------------------- Robert | Daniel | 16 ----------------------------------------- X : number of white spaces - 2 Y : number of white space - 2 it can be any value, but make sure it will be greater than most of
the lengths of the property displayed in that column
对于每个学生,对于第一个单元格(nom),您应首先打印他的名字,然后获得打印名称PN的长度(printf&#39; s返回值),并打印(X-PN)空格,然后你添加管道字符|。 你为下一个prenom属性做同样的事情,最后你打印\ n换一个新行。
Id