-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproof.c
More file actions
138 lines (98 loc) · 4.6 KB
/
proof.c
File metadata and controls
138 lines (98 loc) · 4.6 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdbool.h>
#include "include/string.h"
string proof_create_string(char*);
void proof_destroy_string(string*);
void proof_reserve_string(string);
void proof_print_string(string);
void proof_length_string(string);
void proof_capacity_string(string);
void proof_clear_string(string);
void proof_string_at(string, long);
void proof_string_set(string, long, char);
void proof_string_append(string, char*);
void proof_string_insert(string, long, char*);
void proof_string_delete(string, long, long);
void proof_string_convert_char(string, char*);
int main(){
string str_new = proof_create_string("Hola");
proof_print_string(str_new);
proof_length_string(str_new);
printf("-----------------\n\n");
proof_string_append(str_new, " amigo");
proof_print_string(str_new);
proof_length_string(str_new);
return 0;
}
string proof_create_string(char* data){
return create_string(data);
}
void proof_destroy_string(string* data){
Status status = destroy_string(data);
if(status == ERR_NULL_PTR) printf("ERROR: puntero nulo\n");
else if(status == ERR_NULL_PTR_STR) printf("ERROR: puntero al string nulo\n");
else printf("OK: string liberado\n");
}
void proof_print_string(string data){
Status status = print_string(data);
if(status == ERR_NULL_PTR) printf("ERROR: no se puede imprimir ya que el puntero es nulo\n");
else if(status == ERR_STR_EMPTY) printf("ERROR: el string esta vacio\n");
}
void proof_length_string(string data){
long length = 0;
Status status = length_string(data, &length);
if(status == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else printf("OK: longitud de la cadena: %ld\n",length);
}
void proof_capacity_string(string data){
long ptr_capacity = 0;
Status status = capacity_string(data, &ptr_capacity);
if(status == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else printf("OK: la capacidad del string es: %ld\n", ptr_capacity);
}
void proof_clear_string(string data){
Status status = clear_string(data);
if(status == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else if(status == ERR_NULL_PTR_STR) printf("ERROR: fallo el memory allocator\n");
else printf("OK: string limpiado correctamente\n");
}
void proof_string_at(string data, long index){
char c;
Status status = string_at(data, index, &c);
if(status == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else if(status == ERR_STR_EMPTY) printf("ERROR: string vacio\n");
else if(status == ERR_INDEX_OUT_RANGE) printf("ERROR: el indice pasado por argumento esta fuera de rango\n");
else printf("OK: Este es el caracter en la posicion pasada por argumento: %c\n",c);
}
void proof_string_set(string data, long index, char c){
Status status = string_set(data, index, c);
if(status == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else if(status == ERR_STR_EMPTY) printf("ERROR: string vacio\n");
else if(status == ERR_INDEX_OUT_RANGE) printf("ERROR: el indice pasado por argumento esta fuera de rango\n");
else printf("OK: El caracter pasado por argumento se modifico correctamente en la cadena\n");
}
void proof_string_append(string string, char* data){
Status append = string_append(string, data);
if(append == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else if(append == ERR_NULL_PTR_MEMRY) printf("ERROR: fallo del realloc\n");
else printf("OK: string concatenado\n");
}
void proof_string_insert(string string, long index, char* data){
Status insert = string_insert(string, index, data);
if(insert == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else if(insert == ERR_NULL_PTR_MEMRY) printf("ERROR: fallo del realloc\n");
else if(insert == ERR_INDEX_OUT_RANGE) printf("ERROR: index no es correcto\n");
else printf("OK: string insertado\n");
}
void proof_string_delete(string data, long index, long length){
Status status = string_delete(data, index, length);
if(status == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else if(status == ERR_INDEX_OUT_RANGE) printf("ERROR: index no es correcto\n");
else if(status == ERR_LEN_OUT_RANGE) printf("ERROR: la longitud pasada por argumento esta fuera de rango\n");
else printf("OK: string eliminado correctamente en la posicion indicada\n");
}
void proof_string_convert_char(string string, char* string_converted){
Status status = string_convert_char(string, string_converted);
if(status == ERR_NULL_PTR) printf("ERROR: puntero al string nulo\n");
else printf("OK: string convertido a char*");
}