summaryrefslogtreecommitdiff
path: root/ch2
diff options
context:
space:
mode:
authorAdam Carpenter <gitlab@53hor.net>2019-07-23 12:46:59 -0400
committerAdam Carpenter <gitlab@53hor.net>2019-07-23 12:46:59 -0400
commitfa996dc786d26afc508d637c565ec401f6b5ddb9 (patch)
treef22a2d2da588eece52f88c8d0d1e8c7b926d8869 /ch2
parent8560bf95251098184ab4dfcf11a39d0954105235 (diff)
downloadlearning-c-fa996dc786d26afc508d637c565ec401f6b5ddb9.tar.xz
learning-c-fa996dc786d26afc508d637c565ec401f6b5ddb9.zip
Broke up character lowering from string lowering.
Diffstat (limited to 'ch2')
-rw-r--r--ch2/2-10.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/ch2/2-10.c b/ch2/2-10.c
index 619e2d1..3c6b0cc 100644
--- a/ch2/2-10.c
+++ b/ch2/2-10.c
@@ -2,21 +2,26 @@
#define MAX_LEN 20
-void lower(char* source, char* dest);
+void lower_str(char source[], char dest[]);
+char lower_char(char c);
int main() {
- char* s = "This Is A Test.";
- char lower_s[MAX_LEN];
- lower(s, lower_s);
- printf("%s -> %s\n", s, lower_s);
+ char s[] = "This Is A Test.";
+ char lowered[MAX_LEN];
+ lower_str(s, lowered);
+ printf("%s -> %s\n", s, lowered);
return 0;
}
-void lower(char* source, char* dest) {
+void lower_str(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] = lower_char(source[i]);
dest[i] = '\0';
}
+
+char lower_char(char c) {
+ return c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c;
+}