1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include<stdio.h>
#include<stdlib.h>
#define TAILLE_MAX 1000 // Tableau de taille 1000
#define TAILLE_LIG 9999 //Nombre MAXIMUM DE LIGNE ds un fichier
#define TAILLE_COL 999//Nombre maximum de coloonne ds un fichier
int main(int argc, char *argv[])
{
int i;
char tableau[TAILLE_LIG][TAILLE_COL];
FILE* fichier = NULL;
char chaine[TAILLE_MAX] = ""; // Chaîne vide de taille TAILLE_MAX
fichier = fopen("test.txt", "r");
if (fichier != NULL)
{
while((fgets(chaine, TAILLE_MAX, fichier)!=NULL)&&i<TAILLE_LIG) // On lit maximum TAILLE_MAX caractères du fichier, on stocke le tout dans "chaine"
{
printf("%s", chaine); // On affiche la chaîne
strcpy(tableau,chaine);
i++;
}
fclose(fichier);
}
return 0;
} |
Partager