summaryrefslogblamecommitdiff
path: root/ch2/2-10.c
blob: e63071875cdfa4a0a0adde7b08977179fc5a9944 (plain) (tree)
1
2
3
4
5
6
7
8



                  

                                           

            



                                     


             
                                            

          
                               
                                        


                   



                                                    
#include <stdio.h>

#define MAX_LEN 20

void lower_str(char source[], char dest[]);
char lower_char(char c);

int main() {
    char s[] = "This Is A Test.";
    char lowered[MAX_LEN];
    lower_str(s, lowered);
    printf("%s -> %s\n", s, lowered);
    return 0;
}

void lower_str(char source[], char dest[]) {
    int i;

    for (i = 0; source[i]; i++)
        dest[i] = lower_char(source[i]);

    dest[i] = '\0';
}

char lower_char(char c) {
    return c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c;
}