-
Notifications
You must be signed in to change notification settings - Fork 0
/
libreria.c
111 lines (92 loc) · 1.9 KB
/
libreria.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
char * reemplazar(char * cadena, char * original, char *reemplazo) {
int largo = strlen(cadena);
char * ret = malloc(largo * sizeof(char));
int i = 0, j = 0;
while (i < largo) {
if (cadena[i] != *original) {
ret[j++] = cadena[i];
} else {
if ((*reemplazo) != "") {
ret[j++] = *reemplazo;
}
}
i++;
}
ret[j] = '\0';
return ret;
}
char * quitarEspacios(char * cadena) {
int largo = strlen(cadena);
char * ret = malloc(largo * sizeof(char));
int i = 0, j = 0;
while (i < largo) {
if (cadena[i] != ' ') {
ret[j++] = cadena[i];
}
i++;
}
ret[j] = '\0';
return ret;
}
char * copiar(char * str) {
int largo = strlen(str), i = 0;
char * ret = malloc(largo * sizeof(char));
while (str[i] != '\0') {
ret[i] = str[i++];
}
ret[i] = '\0';
return ret;
}
char * primeraParte(char * transicion) {
char * sinEspacios = quitarEspacios(transicion);
char * ret = malloc(10 * sizeof(char));
int i = 0;
while (sinEspacios[i] != '-') {
if ((i % 10) == 0) {
ret = realloc(ret, (i + 10) * sizeof(char));
}
ret[i] = sinEspacios[i++];
}
ret[i] = '\0';
return ret;
}
char * segundaParte(char * transicion) {
char * sinEspacios = quitarEspacios(transicion);
char * ret = '\0';
int i = 0, j = 0;
while(sinEspacios[i] != '>')
i++;
i++;
while (sinEspacios[i] != '\0') {
if ((j % 10) == 0) {
ret = realloc(ret, (j + 10) * sizeof(char));
}
ret[j++] = sinEspacios[i++];
}
ret[j] = '\0';
return ret;
}
char * crearNombreEstado(int nroEstado) {
int digits;
if(nroEstado == 0) {
digits = 1;
} else {
digits = log10((double)nroEstado) + 1;
}
char * ret = malloc((5+digits)*sizeof(char));
char * nro = malloc(2*sizeof(char));
ret[0] = 'N';
ret[1] = 'o';
ret[2] = 'd';
ret[3] = 'e';
ret[4] = '\0';
nro[0] = nroEstado + '0';
nro[1] = '\0';
strcat(ret, nro);
return ret;
}