-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-cap_string.c
More file actions
executable file
·53 lines (45 loc) · 884 Bytes
/
6-cap_string.c
File metadata and controls
executable file
·53 lines (45 loc) · 884 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
#include "main.h"
/**
* isSeparator - check if passed char is separator on not
*
* @c: char
*
* Return: (1) if char is separator, (0) otherwise
*/
int isSeparator(char c)
{
return (c == ' ' || c == '\n' || c == '.' || c == ',' || c == ';'
|| c == '!' || c == '?' || c == '"' || c == '(' || c == ')'
|| c == '{' || c == '}' || c == '\t');
}
/**
* cap_string - capitalizes all words of a string
*
* @s: pointer to string
*
* Return: string after been capitalized
*/
char *cap_string(char *s)
{
char *sptr; /* pointer to string s */
int flag; /* flag to know if current char is begining of word or not */
sptr = s;
flag = 1;
while (*sptr != '\0')
{
if (isSeparator(*sptr))
{
flag = 1;
}
else if (flag)
{
if (*sptr >= 'a' && *sptr <= 'z')
{
*sptr = 'A' + (*sptr - 'a');
}
flag = 0;
}
++sptr;
}
return (s);
}