-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-capitalize.c
More file actions
48 lines (38 loc) · 756 Bytes
/
Copy path4-capitalize.c
File metadata and controls
48 lines (38 loc) · 756 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
#include "main.h"
void capitalize(char* str);
/**
* Question 4: Capitalize Words
*
* Write a program that accepts a string as input,
* capitalizes the first letter of each word in the
* string, and then returns the result string.
*
*/
void capitalize(char* str)
{
int i = 0;
/* Capitalize the first character of the string */
if (str[i] != '\0')
{
str[i] = toupper(str[i]);
i++;
}
/* Capitalize the first character after each space */
while (str[i] != '\0')
{
if (str[i-1] == ' ' && str[i] != ' ')
{
str[i] = toupper(str[i]);
}
i++;
}
}
int main()
{
char str[MAX_LENGTH];
printf("Enter the string: ");
fgets(str, MAX_LENGTH, stdin);
capitalize(str);
printf("Capitalized string: %s", str);
return 0;
}