diff options
-rw-r--r-- | ch2/2-10.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -0,0 +1,22 @@ +#include <stdio.h> + +#define MAX_LEN 20 + +void lower(char* source, char* dest); + +int main() { + char* s = "This Is A Test."; + char lower_s[MAX_LEN]; + lower(s, lower_s); + printf("%s -> %s\n", s, lower_s); + return 0; +} + +void lower(char* source, char* dest) { + int i; + + for (i = 0; source[i] != '\0'; i++) + dest[i] = source[i] >= 'A' && source[i] <= 'Z' ? source[i] - 'A' + 'a' : source[i]; + + dest[i] = '\0'; +} |