Created
August 30, 2018 09:05
-
-
Save kupp1/c51937aa4f2327fd3e5ffa9b9148bb5b to your computer and use it in GitHub Desktop.
UniLecs #121. cAPS LOCK
This file contains hidden or 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
| #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; | |
| } |
This file contains hidden or 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
| 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