122 lines
1.9 KiB
Plaintext
122 lines
1.9 KiB
Plaintext
----- TP22 : Fichiers (encore) -----
|
|
|
|
1.
|
|
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
|
|
int main(int argc, char** argv) {
|
|
FILE* fichier = NULL;
|
|
char* lu;
|
|
char* contenu;
|
|
int compteur = 1;
|
|
fichier = fopen(argv[1], "r");
|
|
if (fichier == NULL) {
|
|
printf("Erreur d'écriture");
|
|
return EXIT_FAILURE;
|
|
}
|
|
lu = fgets(contenu, 1000, fichier);
|
|
while (lu != NULL) {
|
|
printf("%d ", compteur);
|
|
printf(contenu);
|
|
putchar('\n');
|
|
lu = fgets(contenu, 1000, fichier);
|
|
compteur++;
|
|
}
|
|
fclose(fichier);
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
2.
|
|
|
|
int main(void) {
|
|
/* Déclaration des tableaux */
|
|
int t1[2][5];
|
|
int t2[3][5];
|
|
int t3[5][5];
|
|
int compteur;
|
|
/* Remplissage des tableaux */
|
|
int i;
|
|
int j;
|
|
/* t1 */
|
|
for (i = 0; i != 2; i++) {
|
|
for (j = 0; j != 5; j++) {
|
|
t1[i][j] = j + 1;
|
|
}
|
|
}
|
|
/* t2 */
|
|
compteur = 1;
|
|
for (i = 0; i != 3; i++) {
|
|
for (j = 0; j != 5; j++) {
|
|
t2[i][j] = compteur;
|
|
compteur++;
|
|
}
|
|
}
|
|
/* t3 */
|
|
compteur = 0;
|
|
for (i = 0; i != 5; i++) {
|
|
for (j = 0; j != 5; j++) {
|
|
if (j >= i) {
|
|
t3[i][j] = 0;
|
|
}
|
|
else {
|
|
t3[i][j] = 1 + j;
|
|
}
|
|
}
|
|
}
|
|
/* Affichage des tableaux */
|
|
/* t1 */
|
|
for (i = 0; i != 2; i++) {
|
|
for (j = 0; j != 5; j++) {
|
|
printf("%d ", t1[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
/* t2 */
|
|
for (i = 0; i != 3; i++) {
|
|
for (j = 0; j != 5; j++) {
|
|
printf("%d ", t2[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
/* t3 */
|
|
for (i = 0; i != 5; i++) {
|
|
for (j = 0; j != 5; j++) {
|
|
printf("%d ", t3[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
|
|
/* Inversions lignes-colonnes */
|
|
/* t1 */
|
|
for (j = 0; j != 5; j++) {
|
|
for (i = 0; i != 2; i++) {
|
|
printf("%d ", t1[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
/* t2 */
|
|
for (j = 0; j != 5; j++) {
|
|
for (i = 0; i != 3; i++) {
|
|
printf("%d ", t2[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
/* t3 */
|
|
for (j = 0; j != 5; j++) {
|
|
for (i = 0; i != 5; i++) {
|
|
printf("%d ", t3[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
} |