I want to write a program that outputs whether a string is styled in pascal case, camel case, snake case, kebab case, or none of them.
in the first line, we should take integer n
from input. then, in the next n lines, we should take an integer k
and then a string with no space in each line. k is the size of the string.
here's an example of how each of these case styles look like:
pascal case => HelloWorld
camel case => helloWorld
snake case => hello_world
kebab case => hello-world
e.g: input :
3
11 masterShifu
12 master_shifu
12 MASTER_SHIFU
output:
camel case
snake case
undefined case style
my problem with this program is that I don't know how to find the first letter of each word since there's no space between two different words. this is what i've written so far:
#include <stdio.h>
#include <ctype.h>
int
main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int k;
scanf("%d ", &k);
char word[k];
gets(word[k]);
int count = 0;
if (isupper(word[0]) == 1) {
for (int i = 1; i < n; i++) {
if (isupper(word[i]) == 1) {
count++;
}
}
if (count == k)
printf("Undefined Case Style\n");
else
printf("PascalCase\n");
}
else {
int c = 0,
s = 0,
count = 0;
for (int i = 0; i < n; i++) {
if (word[i] == '-') {
c++;
printf("kebab-case\n");
break;
}
else if (word[i] == '_') // snake case
{
s++;
printf("snake_case\n");
break;
}
else if (isupper(word[i]) == 1) // camel case
{
count++;
printf("camelCase\n");
break;
}
}
if (c == 0 && s == 0)
printf("Undefined Case Style\n");
}
}
return 0;
}