-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.c
74 lines (67 loc) · 1.2 KB
/
string.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
//string functions
#include <stdio.h>
#include <stdlib.h>
int my_strlen(char *c){
int i;
for(i=0;c[i]!= '\0';i++);
return i;
}
void mystrcpy(char *s,char *d){
int i=0;
for(i=0;s[i]!='\0';i++){
d[i]=s[i];
}
d[i]='\0';
}
int mystrcmp(char *s, char *d){
int i = 0;
while (s[i] == d[i] && s[i])
i++;
return s[i] || d[i] ? i : -1;
}
int str2upper(char *s){
int i,upper=0;
for(i=0;s[i]!= '\0';i++){
if(s[i]>='a' && s[i]<='z'){
s[i]=s[i]-32;
upper ++;
}
}
return upper;
}
int str2lower_(char *s){
int i,lower=0;
for(i=0;s[i]!= '\0';i++){
if(s[i]>='A' && s[i]<='Z'){
s[i]=s[i]+32;
lower ++;
}
}
return lower;
}
int str_strip_numbers(unsigned char *s) {
int i, j,l=0;
for(i = 0; s[i] != '\0'; ++i)
{
while (s[i]>='0' && s[i]<='9')
{
for(j = i; s[j] != '\0'; ++j)
{
s[j] = s[j+1];
}
s[j] = '\0';
}
}
for(l=0;s[l]!= '\0';l++);
return l;
}
char * strdupl(char *s){
char *d;
d=(char *) malloc(16);
int i=0;
for(i=0;s[i]!='\0';i++){
d[i]=s[i];
}
d[i]='\0';
return d;
}