#include <stdio.h>
typedef char* string;
const int capital_distance = 'a' - 'A';
void switch_capitals(string source)
{
for (char *c = source; *c != '\0'; c++) {
if (*c >= 'A' && *c <= 'Z') {
*c = *c + capital_distance;
} else if (*c >= 'a' && *c <= 'z') {
*c = *c - capital_distance;
}
}
}
void switch_capitals_safe(string source, string destination, int len)
{
int i = 0;
for (; i != len; i++) {
if (source[i] >= 'A' && source[i] <= 'Z')
destination[i] = source[i] + capital_distance;
else if (source[i] >= 'a' && source[i] <= 'z')
destination[i] = source[i] - capital_distance;
else
destination[i] = source[i];
}
destination[i] = '\0';
}
int main(void) {
char hello[] = "lol PCJ hivemind caught in the local minima of the jerk attractor, CANNOT escape UnJeRk tRaP";
printf("%s - ", hello);
switch_capitals(hello);
printf("%s\n", hello);
string lol = "lOL nO GeNeRiCs";
char dest[16];
switch_capitals_safe(lol, dest, 13);
printf("%s - %s\n", lol, dest);
}