-
Notifications
You must be signed in to change notification settings - Fork 368
/
Camel_Case.c
54 lines (50 loc) · 1.47 KB
/
Camel_Case.c
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
/*Name : Atul Kumar
Github username : atul1510
Repositary name : Algorithms
*/
/*Problem Description
Program to convert text sentence in CamelCase format .
Examples:
1] INPUT: "this is camel case"
OUTPUT "thisIsCamelCase"
2] INPUT: "Hi Atul here"
OUTPUT: "hiAtulHere"
Example Explanation */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
int main() {
int testCase;
printf("Enter the no of test cases: ");
scanf("%d", &testCase);
printf("\n");
while (getchar() != '\n'); // Clear the input buffer
while (testCase--) {
char str[1000];
int flag = 0;
printf("Enter a sentence: ");
fgets(str, sizeof(str), stdin);
printf("\nOriginal: %s", str);
for (int i = 0 ; i < strlen(str) ; i++) {
if (i == 0) str[i] = tolower(str[i]); //Converts to lowercase
else if (str[i] == ' ') flag = 1; // Check for spaces in the sentence
else if (flag && str[i] != ' ') {
str[i] = toupper(str[i]); //Converts to uppercase
flag = 0;
}
else str[i] = tolower(str[i]); //Converts to lowercase
}
char camelCase[sizeof(str)];
int i, j = 0;
for (i = 0; str[i] != '\0'; i++) {
if (str[i] != ' ') {
camelCase[j++] = str[i];
}
}
printf("Camel Case: %s\n", camelCase);
printf("\n");
}
return 0;
}