Skip to content

Instantly share code, notes, and snippets.

@kupp1
Created August 30, 2018 09:05
Show Gist options
  • Select an option

  • Save kupp1/c51937aa4f2327fd3e5ffa9b9148bb5b to your computer and use it in GitHub Desktop.

Select an option

Save kupp1/c51937aa4f2327fd3e5ffa9b9148bb5b to your computer and use it in GitHub Desktop.
UniLecs #121. cAPS LOCK
#include <stdio.h>
int main (int argc, char* argv[]) {
if (argc < 2) {
return -1, printf("missing argument\n");
}
for (int i = 1; i < argc; i++) {
while (*argv[i] != '\0') {
if (*argv[i] >= 65 && *argv[i] <= 90)
putchar(*argv[i] + 32);
else if (*argv[i] >= 97 && *argv[i] <= 122)
putchar(*argv[i] - 32);
else
putchar(*argv[i]);
argv[i]++;
}
putchar(32);
}
putchar(10);
return 0;
}
import sys
args = sys.argv[1:]
if args:
text = ' '.join(args)
new_text = ''
for char in text:
code = ord(char)
if code >= 65 and code <= 90:
new_text += chr(code+32)
elif code >= 97 and code <= 122:
new_text += chr(code-32)
else:
new_text += char
print(new_text)
else:
print('No input. Enter text as arguments with spaces.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment