-
Notifications
You must be signed in to change notification settings - Fork 0
/
chezlib.c
57 lines (44 loc) · 1003 Bytes
/
chezlib.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char* lower(const char *str)
{
size_t len = strlen(str);
char* lowStr = (char*)malloc(len + 1);
size_t src;
for (src = len - 1, src = 0; src < len; src++) {
lowStr[src] = tolower(str[src]);
}
lowStr[len] = '\0';
return lowStr;
}
char* substring(const char *str, size_t start, size_t end)
{
size_t len = strlen(str);
char* sub = (char*)malloc(len + 1);
size_t src = 0;
while (start < end && start < len) {
sub[src] = str[start];
src++;
start++;
}
sub[src] = '\0';
return sub;
}
char* upper(const char *str)
{
size_t len = strlen(str);
char* upStr = (char*)malloc(len + 1);
size_t src;
for (src = len - 1, src = 0; src < len; src++) {
upStr[src] = toupper(str[src]);
}
upStr[len] = '\0';
return upStr;
}
int main(){
char s[] = "HELLO WORLD";
printf("%s", lower(s));
return 0;
}