-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCstring.cpp
More file actions
94 lines (78 loc) · 1.49 KB
/
Cstring.cpp
File metadata and controls
94 lines (78 loc) · 1.49 KB
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
#include "Cstring.h"
bool isDigit(char c)
{
if(c>='0' && c<='9')
return true;
return false;
}
bool isLetter(char c)
{
if((c>='a' && c<='z') || (c>='A' && c<='Z'))
return true;
return false;
}
bool isSpace(char c) //maybe don't need
{
if(c==' ')
return true;
return false;
}
int charToInt(char c)
{
int num=0;
if(isDigit(c))
num=c-'0';
return num;
}
unsigned int strLen(const char *s)
{
int i;
for(i=0;*s!='\0';i++,s++);
return i;
}
void append(char* d, const char* s)
{
char* dWalk=d+strLen(d);
for(;*s!='\0';dWalk++,s++)
*dWalk=*s;
*dWalk='\0';
}
void append(char* d, const char* s, int len)
{
char* dWalk=d+strLen(d);
for(int i=0;*s!='\0' && i<len;dWalk++,s++,i++)
*dWalk=*s;
*dWalk='\0';
}
void strCpy(char* d,const char* s)
{
for(;*s!='\0';d++,s++)
*d=*s;
*d='\0';
}
void strCpy(char* d, const char *s, int len)
{
for(int i=0;*s!='\0' && i<len;d++,s++,i++)
*d=*s;
*d='\0';
}
bool strCmp(const char* one, const char* two)
{
const char* walk1=one;
const char* walk2=two;
while(*walk1!='\0' && *walk2!='\0'){
if(*walk1!=*walk2)
return false;
walk1++;walk2++;
}
if(strLen(one)!=strLen(two))
return false;
return true;
}
void getWordFromString(int start, int end, char word[], char src[]){
int i;
for (i = 0; i < end -start; i++){
word[i] = src[i+start];
}
word[i] = '\0';
}