-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.cpp
More file actions
57 lines (42 loc) · 930 Bytes
/
lib.cpp
File metadata and controls
57 lines (42 loc) · 930 Bytes
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
#include <cstring>
#include "lib.h"
void initStr(char *str, int len){
/* initiate a string with a series of null terminators */
for (int i = 0; i < len; i++){
str[i] = 0;
}
}
int countNonZero(char *str, int len){
int count = 0;
for (int i = 0; i < len; i++){
if (str[i] > 0){
count++;
}
}
return count;
}
void appendStr(char *base, const char *addition, int index){
int len = strlen(addition); //length of string to add
int end = len + index; //where to end
// end - index = where to end - where to start
int increment = 0;
// add comma
if (index > 0){
base[index] = ',';
increment = 1;
}
for (int i = 0; i < (end - index); i++){
base[index + i + increment] = addition[i];
}
}
int countChar(char *str, int key){
//checks if single char. key is in str
int count = 0;
int len = strlen(str);
for (int i = 0; i < len; i++){
if (str[i] == key){
count++;
}
}
return count;
}