Citation :
int lecture_exemples(int ***e, int *nb_app, int total)
{
FILE *fp;
char buf[30];
int **e1;
do
{ printf("\n" );
printf("Nom du fichier d'apprentissage : " );
scanf("%s", buf);
if ( (fp = fopen(buf, "r+" ) ) == NULL )
{
printf(" Impossible d'ouvrir le fichier\n" );
}
else
{
int i, j;
fscanf(fp,"%d", nb_app);
/* Allocation des exemples */
if ( (e1 = (int **) malloc(sizeof(int *) * (*nb_app))) == NULL)
{
fclose(fp);
return -1;
}
for(i=0;i<*nb_app;i++)
if( (e1[i] = (int *) malloc(sizeof(int) * total)) == NULL)
{
fclose(fp);
return -1;
}
/* Lecture des exemples */
for(i=0;i<*nb_app;i++)
for(j=0;j<total;j++)
fscanf(fp, "%d", &e1[i][j]);
}
}
while(fp==NULL);
fclose(fp);
*e = e1;
return 0;
}
|