forked from CesarAng28/DataShell
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrolador_Proceso.c
More file actions
79 lines (56 loc) · 1.59 KB
/
controlador_Proceso.c
File metadata and controls
79 lines (56 loc) · 1.59 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "DataShell.h"
void controlador_Proceso(char * archivo)
{
size_t count = 0, columns;
int i,j;
int validacion_nombre;
FILE * archivo_lectura;
char linea_leida[BUFSIZ];
float * Matriz_Datos[BUFSIZ];
float * float_ptr;
float * buffer;
//Corregimos el '\n' que se lee con fgets
modelo_Correccion_Nombre(archivo);
//Validamos si el nombre es correcto.
validacion_nombre = modelo_Valida_Nombre(archivo);
if(validacion_nombre == 0 || validacion_nombre == -1)
{
vista_Error_Menos1();
}
else//Si la validacion salio correctamente, podemos continuar con el proceso.
{
archivo_lectura = modelo_Abre_Archivo(archivo);
while(!feof(archivo_lectura))
{
//Leemos una linea del archivo.
fscanf(archivo_lectura,"%s\n",linea_leida);
//Adecua la cadena para que sea tokenizada
strcpy(linea_leida, controlador_linea(linea_leida));
//La separamos
Matriz_Datos[count] = modelo_Tokenizer(linea_leida,buffer);
count++;
free(buffer);
}
fclose(archivo_lectura);
//Calculamos la cantidad de columnas ayudàndonos con la ultima linea leida.
columns = modelo_Columnas(linea_leida);
printf("%zu columns and %zu rows read\n\n",columns,count);
//EL siguiente bloque de còdigo es para pura verificacion, se borrara en futuras implementaciones.
for(i=0 ; i<count ; i++)
{
float_ptr = Matriz_Datos[i];
for(j=0 ; j<columns; j++)
{
if(j==0)
{
printf("%.0f -> ",float_ptr[j]);
}
else
{
printf("%f ",float_ptr[j]);
}
}
printf("\n");
}
}
}