Table C
Solved
MissRobet
Posted messages
5
Status
Membre
-
[Dal] Posted messages 6373 Status Contributeur -
[Dal] Posted messages 6373 Status Contributeur -
Salut, je veux obtenir un affichage bien ordonné comme un tableau de données. Cependant, voici ce que mon programme affiche, et je ne comprends pas pourquoi cet affichage retourne à la ligne pour afficher les zéros et quelques autres variables, alors que j'ai inséré le \n seulement à la fin de l'affichage de chaque ligne ! Pouvez-vous m'aider à trouver une solution, s'il vous plaît ?
printf("ID reservation\t\tNumero Passeport\t\tNom du voyageur\t\tDate de Naissance\t\tDepartArrivee\t\tVille de destination\t\tPays de destination\t\tVoyage en groupe: choisir 0 ou 1\t\tNumero du Groupe\n");
for (i=0; i<=Nbr_de_Voyages; i++)
{
printf("%i\t\t", Reservation[i]);
printf("%s\t\t", NumPasseport[i]);
printf("%s\t\t", NomVoyageur[i]);
printf("%s\t\t", DateNaisVgr[i]);
printf("%s\t\t", DateDpt[i]);
printf("%s\t\t", DateArv[i]);
printf("%s\t\t", VilleDest[i]);
printf("%s\t\t", PaysDest[i]);
printf("%i\t\t", Grp_V_F[i]);
printf("%i\t\t", NumGrp[i]);
printf("\n");
Il n'y a que la ligne en rouge qui s'affiche sous la forme que j'avais attendue.
}
printf("ID reservation\t\tNumero Passeport\t\tNom du voyageur\t\tDate de Naissance\t\tDepartArrivee\t\tVille de destination\t\tPays de destination\t\tVoyage en groupe: choisir 0 ou 1\t\tNumero du Groupe\n");
for (i=0; i<=Nbr_de_Voyages; i++)
{
printf("%i\t\t", Reservation[i]);
printf("%s\t\t", NumPasseport[i]);
printf("%s\t\t", NomVoyageur[i]);
printf("%s\t\t", DateNaisVgr[i]);
printf("%s\t\t", DateDpt[i]);
printf("%s\t\t", DateArv[i]);
printf("%s\t\t", VilleDest[i]);
printf("%s\t\t", PaysDest[i]);
printf("%i\t\t", Grp_V_F[i]);
printf("%i\t\t", NumGrp[i]);
printf("\n");
Il n'y a que la ligne en rouge qui s'affiche sous la forme que j'avais attendue.
}
1 answer
Instead of using tabs to align the content of your columns, you could use printf with a size specifier.
For example,
Dal
For example,
printf("%7s ",NumPasseport[i]); if you know that your passport numbers will not exceed 7 characters. You should also use shorter column headers that are based on the width of the data in the column; otherwise, it won’t look great, and align them using the same method. Dal
int lmax = 7; printf("%*s ", lmax, NumPasseport[i]);With this method, and by ensuring that your program analyzes the data of a column before displaying its content, to determine the maximum width needed, you can create a program that automatically adjusts the width instead of hardcoding it.
whereas when I only used %.7s ... the result was as follows
I give you indications in the form of examples as repeated several times. It is up to you to do the exercise, not me :-)
The size for the traveler's name, in your case, use up to 20 characters. Of course, if you apply a %7s formatting you will not get the expected result...