-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmstrings.c
134 lines (122 loc) · 2.47 KB
/
mstrings.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
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
#include <string.h>
char _strbuffer[255];
void replace(char* buffer,char* search,char* rpl)
{
char *origin;
char *tmpb;
char *tmps;
char *dst;
origin=buffer;
dst=_strbuffer;
while (*buffer!='\0') {
tmpb=buffer;
tmps=search;
while (*tmpb==*tmps && *tmps!='\0' && *tmpb!='\0') {
tmpb++; tmps++;
}
if (*tmpb!='\0' && *tmps=='\0') {
tmps=rpl;
while (*tmps!='\0') *dst++=*tmps++;
buffer=tmpb; buffer--;
}
else if (*tmpb=='\0' && *tmps=='\0') {
tmps=rpl;
while (*tmps!='\0') *dst++=*tmps++;
buffer=tmpb; buffer--;
}
else *dst++=*buffer;
buffer++;
}
*dst='\0';
strcpy(origin,_strbuffer);
}
unsigned char ord(char x)
{
return x;
}
int length(char *instr)
{
return strlen(instr);
}
int pos(char key,char* strng)
{
int ret;
int i;
ret=0;
i=1;
while (*strng!='\0') {
if (*strng==key && ret==0) ret=i;
i++;
strng++;
}
return ret;
}
char* copy(char* source,int pos,int length)
{
char* cptr;
while (pos!=1 && *source!='\0') { source++; pos--; }
cptr=_strbuffer;
while (length!=0 && *source!='\0') {
*cptr++=*source++;
length--;
}
*cptr='\0';
return _strbuffer;
}
int val(char* buffer)
{
int total;
total=0;
while (*buffer>='0' && *buffer<='9') {
total*=10;
switch (*buffer++) {
case '0':total+=0; break; case '1':total+=1; break;
case '2':total+=2; break; case '3':total+=3; break;
case '4':total+=4; break; case '5':total+=5; break;
case '6':total+=6; break; case '7':total+=7; break;
case '8':total+=8; break; case '9':total+=9; break;
}
}
return total;
}
char* left(char* buffer,int count)
{
char* dest;
dest=_strbuffer;
while (*buffer!='\0' && count>0)
*dest++=*buffer++;
*dest='\0';
return _strbuffer;
}
char* remspace(char* buffer)
{
char *dest;
dest=_strbuffer;
while (*buffer==' ') buffer++;
strcpy(dest,buffer);
return _strbuffer;
}
char* trailspace(char* buffer)
{
// char *dest;
// dest=_strbuffer;
strcpy(_strbuffer,buffer);
while (strlen(_strbuffer)>0 && _strbuffer[strlen(_strbuffer)-1]==' ')
_strbuffer[strlen(_strbuffer)-1]='\0';
return _strbuffer;
}
char upcase(char in)
{
if (in>='a' && in<='z') return in-32; else return in;
}
char* upper(char* buffer)
{
char *dest;
dest=_strbuffer;
strcpy(_strbuffer,buffer);
while (*dest|='\0') {
if (*dest>='a' && *dest<='z') *dest=(*dest)-32;
dest++;
}
return _strbuffer;
}