Skip to content

Instantly share code, notes, and snippets.

@BrandonIrizarry
Last active December 20, 2020 00:11
Show Gist options
  • Save BrandonIrizarry/5a2e51cebe9ede5bec18b6c0b4f8b611 to your computer and use it in GitHub Desktop.
Save BrandonIrizarry/5a2e51cebe9ede5bec18b6c0b4f8b611 to your computer and use it in GitHub Desktop.
Use C to convert command-line arguments to Spongebob-case.
/*
Small, fun proof-of-concept:
Given a command-line string, convert each argument to
SpongeBob-case. Invoking './spongebob spongebob meme' prints
'sPoNgEbOb mEmE' to stdout.
*/
#include <stdio.h>
#include <ctype.h>
int main (int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++) {
char *str = argv[i];
int do_lowercase = 1;
int j;
for (j = 0; str[j]; j++) {
if (do_lowercase)
str[j] = tolower(str[j]);
else
str[j] = toupper(str[j]);
do_lowercase = !do_lowercase;
}
printf("%s ", str);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment