Last active
December 20, 2020 00:11
-
-
Save BrandonIrizarry/5a2e51cebe9ede5bec18b6c0b4f8b611 to your computer and use it in GitHub Desktop.
Use C to convert command-line arguments to Spongebob-case.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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