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> | |
void replace(char *dest, char *str) | |
{ | |
while (*str != '\0') { | |
if (64 < *str && *str < 91) { | |
*dest = *str + 32; | |
} else if (96 < *str && *str < 123) { | |
*dest = *str - 32; | |
} else { | |
*dest = *str; | |
} | |
str++; | |
dest++; | |
} | |
*dest = '\0'; | |
} | |
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 wordCount; | |
int i; | |
for (i = 1; argv[i] != NULL ; i++) { | |
wordCount = strlen(argv[i]); | |
char str[wordCount+1]; | |
char dest[wordCount+1]; | |
strcpy(str, argv[i]); | |
replace(dest, str); | |
print_data(dest, str); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment