forked from CesarAng28/DataShell
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataShell.c
More file actions
83 lines (78 loc) · 2.31 KB
/
DataShell.c
File metadata and controls
83 lines (78 loc) · 2.31 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
80
81
82
83
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "DataShell.h"
int DataShell_leer_arrayofstruct(char nombre[], param array[])
{
FILE *archivo=NULL;
int i=0;
char linea[1024];
char *saveptr, *token=NULL;
archivo=fopen(nombre, "rt");
if(archivo!=NULL)
{
while(!feof(archivo))
{
fgets(linea,1024,archivo);
if(feof(archivo))break;
if(strlen(linea)>0)
linea[strlen(linea)-1]='\0';
token = strtok_r(linea, ",", &saveptr);
strcpy(array[i].nombre, token);
token = strtok_r(saveptr, ",", &saveptr);
array[i].accion=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].comedia=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].romance=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].terror=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].ficcion=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].drama=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].historia=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].documental=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].arte=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
array[i].animada=strtod(token, NULL);
token = strtok_r(saveptr, ",", &saveptr);
strcpy(array[i].clasf, token);
i++;
saveptr=NULL;
}
fclose(archivo);
}
return i;
}
void DataShell_leer_matriz(char nombre[], double matriz[10][30], int fil, int col)
{
FILE *archivo=NULL;
int i=0, j=0;
char linea[1024];
char *saveptr, *token=NULL;
archivo=fopen(nombre, "rt");
if(archivo!=NULL)
{
for(i=0;i<fil;i++)
{
fgets(linea,1024,archivo);
if(feof(archivo))break;
if(strlen(linea)>0)
linea[strlen(linea)-1]='\0';
token = strtok_r(linea, ",", &saveptr);
matriz[i][0]=strtod(token, NULL);
for(j=1;j<col;j++)
{
token = strtok_r(saveptr, ",", &saveptr);
matriz[i][j]=strtod(token, NULL);
}
saveptr=NULL;
}
fclose(archivo);
}
return;
}