-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.c
More file actions
57 lines (49 loc) · 1.04 KB
/
string.c
File metadata and controls
57 lines (49 loc) · 1.04 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
#include "shell.h"
/**
* count_Words - A function that counts the number of
* words in the string
* @inputString: The string containing the words
* Return: Number of words in string
*/
int count_Words(char *inputString)
{
int index = 0, wordCount = 0, state = 0;
while (inputString[index])
{
if (inputString[index] == ' '
|| inputString[index] == '\n'
|| inputString[index] == '\t')
state = 0;
else if (state == 0)
{
state = 1;
wordCount++;
}
index++;
}
return (wordCount);
}
/**
* countDelimiters - A function that counts the
* occurrences of delimiters in a string
* @inputString: The string to search for delimiters
* @delimiters: The string containing delimiters to find
* in the input string
* Return: The number of delimiter in the string
*/
int countDelimiters(char *inputString, char *delimiters)
{
int i = 0, j = 0, deli_count = 0;
while (delimiters[i])
{
j = 0;
while (inputString[j])
{
if (inputString[j] == delimiters[i])
deli_count++;
j++;
}
i++;
}
return (deli_count);
}