Cargar datos de un fichero en C
Hola a todos,
Os explico, he conseguido leer datos de un archivo y almacenarlos en variables de la siguiente forma:
void Lee_de_fichero ( )
{
int aux;
char texto[100];
if ( ( infile = fopen ( "entrada.txt" , "rt" )) == NULL )
{
ErrorFatal("Fichero entrada.txt no encontrado");
}
fgets( texto, 100, infile) ;
aux = sscanf(texto, "%d %d %f %f %d %dn", &POS_I, &POS_J, &LIM_S, &LIM_I, &GRABA, &MEDIDA);
fclose(infile);
}
Pero de este modo solo consigo leer una línea de codigo y lo que quiero es leer varias lineas de varios datos (una matriz).
Intenté hacerlo del siguiente modo:
do
{
fgets( texto, 100, infile);
aux = sscanf(texto, "%d %d %f %f %d %dn", &POS_I, &POS_J, &LIM_S, &LIM_I, &GRABA, &MEDIDA);
for(i=0;i<=8;i++)
{
for(j=0;j<=6;j++)
{
Ls[i][j] = LIM_S;
Li[i][j] = LIM_I;
grabar[i][j] = GRABA;
tipo_medida[i][j] = MEDIDA;
}
}
}while( !feof(infile) );
fclose(infile);
Pero el programa se me queda colgado.
Gracias
Os explico, he conseguido leer datos de un archivo y almacenarlos en variables de la siguiente forma:
void Lee_de_fichero ( )
{
int aux;
char texto[100];
if ( ( infile = fopen ( "entrada.txt" , "rt" )) == NULL )
{
ErrorFatal("Fichero entrada.txt no encontrado");
}
fgets( texto, 100, infile) ;
aux = sscanf(texto, "%d %d %f %f %d %dn", &POS_I, &POS_J, &LIM_S, &LIM_I, &GRABA, &MEDIDA);
fclose(infile);
}
Pero de este modo solo consigo leer una línea de codigo y lo que quiero es leer varias lineas de varios datos (una matriz).
Intenté hacerlo del siguiente modo:
do
{
fgets( texto, 100, infile);
aux = sscanf(texto, "%d %d %f %f %d %dn", &POS_I, &POS_J, &LIM_S, &LIM_I, &GRABA, &MEDIDA);
for(i=0;i<=8;i++)
{
for(j=0;j<=6;j++)
{
Ls[i][j] = LIM_S;
Li[i][j] = LIM_I;
grabar[i][j] = GRABA;
tipo_medida[i][j] = MEDIDA;
}
}
}while( !feof(infile) );
fclose(infile);
Pero el programa se me queda colgado.
Gracias
