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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int cpt; int i; char mot[25]={0};
char *tab;
FILE *fichier = NULL;
fichier = fopen("fich_mot.txt", "r+");
cpt=0;
while(!feof(fichier))
{
fscanf(fichier,"%s",mot);
cpt++;
}
tab =(char*)malloc(cpt*sizeof(char));
//Tester l'ouverture du fichier
if(fichier != NULL)
{
rewind(fichier);//renvoyer à la position 0 dans le fichier
i = 0;
while (!feof(fichier))
{
mot = "";
fscanf(fichier,"%s",mot);
tab[i]=mot;
i++;
}
printf("les elements du tableau construits sont : \n");
for(i=1 ; i<cpt ;i++)
{
printf ("tab[%d] = %s ",i,tab[i]);
printf("\n");
}
free(tab);
fclose(fichier);
}
else
{
printf("Impossible d'ouvrir le fichier fich_entier.txt");
}
getch();
return 0;
} |
Partager