blob: dff3b3f9bf953089de5cb324b1f775e07f78ee3e (
plain)
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
|
#include <string.h>
#include <assert.h>
#include <stdlib.h>
char *str_delete_at(const char *str, const int pos)
{
char *tmp = malloc(sizeof(char) * (strlen(str) + 1));
assert(tmp != NULL);
strcpy(tmp, str);
int len = strlen(str);
if (pos >= len)
return tmp;
for (int i = 0; i < len; ++i)
{
if (i >= pos)
tmp[i] = tmp[i + 1];
}
return tmp;
}
size_t str_count_occ(const char *str, const char ch)
{
size_t count = 0;
for (int i = 0; str[i] != '\0'; ++i)
{
if (str[i] == ch)
count += 1;
}
return count;
}
/* Return random integer between lower bound bound_l (inclusive) and upper bound bound_u (exclusive) */
int int_rand(const int bound_l, const int bound_u)
{
return bound_l + (rand() % bound_u);
}
|