-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path6-cap_string.c
More file actions
executable file
·42 lines (40 loc) · 995 Bytes
/
6-cap_string.c
File metadata and controls
executable file
·42 lines (40 loc) · 995 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
#include "main.h"
/**
* cap_string - Capitalizes first letter of all words of a string
* @s: The string to check
* Return: Pointer to string
* ASCII values:
* space( ): 32, tabulation(\t): 9, new line(\n): 10, comma(,): 44,
* semicolon(;): 59, dot(.): 46, exclamation mark(!): 33,
* question mark(?): 63, double quote("): 34, parenthesis((): 40,
* parenthesis()): 41, curly braces({): 123, curly braces(}): 125.
*/
char *cap_string(char *s)
{
int i;
for (i = 0; s[i] != '\0'; i++)
{
if (s[i] >= 97 && s[i] <= 122)
{
if (i == 0)
s[i] = s[i] - 32;
if (s[i - 1] == 32 || s[i - 1] == 9 || s[i - 1] == 10 || s[i - 1] == 44)
{
s[i] = s[i] - 32;
}
else if (s[i - 1] == 59 || s[i - 1] == 46 || s[i - 1] == 33)
{
s[i] = s[i] - 32;
}
else if (s[i - 1] == 63 || s[i - 1] == 34 || s[i - 1] == 40)
{
s[i] = s[i] - 32;
}
else if (s[i - 1] == 41 || s[i - 1] == 123 || s[i - 1] == 125)
{
s[i] = s[i] - 32;
}
}
}
return (s);
}