Last active
August 29, 2015 14:03
-
-
Save y0t4/e37ab3ecb8143003b3d5 to your computer and use it in GitHub Desktop.
てきとーに
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
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#define DIFF_UPPER_LOWER ('a'-'A'); | |
void replace(char *dest, char *str) | |
{ | |
int length = strlen(str); | |
for (int i=0; i < length; i++) { | |
if ( 'A'<=str[i] && str[i]<='Z' ) { | |
dest[i] = str[i] + DIFF_UPPER_LOWER; | |
} else if ( 'a'<=str[i] && str[i]<='z' ) { | |
dest[i] = str[i] - DIFF_UPPER_LOWER; | |
} else { | |
dest[i] = str[i]; | |
} | |
} | |
} | |
void print_data(char *dest, char *str) | |
{ | |
printf("str : %s\n", str); | |
printf("dest: %s\n", dest); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
if (argc == 1) { | |
fprintf(stderr, "Usage: ./a.out [string] [string] ...\n"); | |
exit(1); | |
} | |
int length; | |
char *str; | |
char *dest; | |
for (int i = 1; argv[i] != NULL; i++) { | |
length = strlen(argv[i])+1; | |
str = (char *)calloc(length, sizeof(char)); | |
dest = (char *)calloc(length, sizeof(char)); | |
strncpy(str, argv[i], length); | |
replace(dest, str); | |
print_data(dest, str); | |
free(str); | |
free(dest); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment