-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.h
80 lines (64 loc) · 1.52 KB
/
functions.h
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
#include <ctype.h>
#include <assert.h>
typedef struct EBR {
char part_status;
char part_fit;
int part_start;
int part_size;
int part_next;
char part_name [16];
} ebr;
typedef struct PARTITIONS {
char part_status;
char part_type;
char part_fit;
int part_start;
int part_size;
char part_name [16];
} partition;
typedef struct MBR {
int mbr_tamaño;
int mbr_fecha_creacion;
int mbr_disk_signature;
partition mbr_partition_1;
partition mbr_partition_2;
partition mbr_partition_3;
partition mbr_partition_4;
} mbr;
void removeChar(char *str, char garbage) {
char *src, *dst;
for (src = dst = str; *src != '\0'; src++) {
*dst = *src;
if (*dst != garbage) dst++;
}
*dst = '\0';
}
void stripLeadingAndTrailingSpaces(char* string){
assert(string);
/* First remove leading spaces */
const char* firstNonSpace = string;
while(*firstNonSpace != '\0' && isspace(*firstNonSpace))
{
++firstNonSpace;
}
size_t len = strlen(firstNonSpace)+1;
memmove(string, firstNonSpace, len);
/* Now remove trailing spaces */
char* endOfString = string + len;
while(string < endOfString && isspace(*endOfString))
{
--endOfString ;
}
*endOfString = '\0';
}
void remove_extra_spaces(char* str) {
int i,x;
for(i=x=1; str[i]; ++i)
if(!isspace(str[i]) || (i>0 && !isspace(str[i-1])))
str[x++] = str[i];
str[x] = '\0';
stripLeadingAndTrailingSpaces(str);
}
#define bool int
#define true 1
#define false 0