-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasecon_utils.c
110 lines (91 loc) · 2.13 KB
/
basecon_utils.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
int power(int base, int p){ //this user defined function takes a number and power vaue and returns base^p
int result = 1;
if(p){ //if the value is not 0, it runs the statement below
for(int i = p; i > 0; i--){ //i i set to p and condition checks if i is greater than 1 if yes...it runs the statement
// in the for block which is base is multiplied by base until i is equal 1
result *= base;
}
return result;
}
else{ //if the value of p is 0
return result; //returns 1
}
}
int isLower(int ch){
if(ch >= 97 && ch <= 122)
return 1;
return 0 ;
}
int isDigit(int ch){
if(ch >= 48 && ch <= 57)
return 1;
return 0;
}
int Strlen(const char* string){
int len = 0;
while (*string != '\0'){
len++;
string++;
}
return len;
}
int Strcmp(const char* string1, const char* string2){
int len_string1 = Strlen(string1);
int len_string2 = Strlen(string2);
if((len_string1 - len_string2) == 0){
for(int i = 0; i < len_string1; i++){
if(*(string1+i) == *(string2+i))
len_string2--;
}
if(len_string2 == 0)
return 0;
else
return 1;
} else{
return 1;
}
}
int AtoI(const char* str){ //changes number stored in a string to integer
int res = 0;
char *ptr = (char*)str;
while (*ptr != '\0') {
if (isDigit(*ptr)) {
// Integer part
res *= 10; // Shift the previous digits to the left
res += *ptr - 48; // Add the new one
}
ptr++;
}
return res;
}
void reverse(char*str){
int len = 0, temp;
char*ptr = str;
while(*ptr != '\0'){
len++;
ptr++;
}
int i = 0, j = len-1;
while(i < j){
temp = *(str+i);
*(str+i) = *(str+j);
*(str+j) = temp;
++i;
--j;
}
}
int delete(char*data, int index, int length){
int i;
for (i = index; i < (length)-1; i++)
{
*(data+i) = *(data+i+1);
}
*(data+i) = '\0';
length--;
return length;
}
void memreset(char*data, int len){
for(int i = 0; i < len; i++){
*(data+i) = '\0';
}
}