/
2023_08-Exercise.c
66 lines (62 loc) · 936 Bytes
/
2023_08-Exercise.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
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
const int count = 7;
char *variable[] = {
"readInputMeter",
"cyclical_redundancy_check",
"bumpyRide",
"search_for_node",
"string_convert",
"divideByZeroError",
"giveUpAndExplode"
};
int x;
char *n;
for(x=0; x<count; x++ )
{
printf("%25s -> ",variable[x]);
n = variable[x]; /* initialize pointer n */
/* test for the underscore */
if( strchr(variable[x],'_') )
{
/* name is in snake_case */
while( *n )
{
if( *n=='_' )
{
n++;
/* test for overflow */
if( *n=='\0' ) break;
putchar( toupper(*n) );
}
else
{
putchar(*n);
}
n++;
}
}
else
{
/* name is in camelCase */
while( *n )
{
if( isupper(*n) )
{
putchar('_');
putchar( tolower(*n) );
}
else
{
putchar(*n);
}
n++;
}
}
putchar('\n');
}
return(0);
}