-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMystrings.cpp
More file actions
107 lines (94 loc) · 1.36 KB
/
Mystrings.cpp
File metadata and controls
107 lines (94 loc) · 1.36 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
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
#include "Mystrings.h"
int my_strlen(char* str)
{
int counter = 0;
while (str[counter] != '\0')
{
counter++;
}
return counter;
}
int word_count(char* str)
{
int word_number = str[0] == '\0' ? 0 : 1;
int index = 0;
while (str[index] != '\0')
{
if (str[index] == 32)
{
word_number++;
}
index++;
}
return word_number;
}
int upper_count(char* str)
{
int upper_counter = 0;
int index = 0;
while (str[index] != '\0')
{
if (str[index] >= 65 && str[index] <= 90)
{
upper_counter++;
}
index++;
}
return upper_counter;
}
int isupper(char letter)
{
if (letter >= 65 && letter <= 90)
{
return 1;
}
else
{
return 0;
}
}
char toupper(char letter)
{
if (letter >= 97 && letter <= 122)
{
letter -= 32;
return letter;
}
else
{
return letter;
}
}
char* capitalize(char* str)
{
if (!isupper(str[0]))
{
str[0] = toupper(str[0]);
}
int index = 0;
while (str[index] != '\0')
{
if (str[index - 1] == 32 && !isupper(str[index]))
{
str[index] = toupper(str[index]);
}
index++;
}
return str;
}
void char_flipper(char *first_char, char *second_char)
{
char temp_char = *first_char;
*first_char = *second_char;
*second_char = temp_char;
}
char* my_strflip(char* str)
{
int lenght = my_strlen(str);
for (int i = 0; i < lenght / 2; i++)
{
char_flipper(&str[i], &str[lenght - 1 - i]);
}
return str;
}