This function takes a string “str” and a variable “mode” as parameters. According to mode’s value the string is converted into lowercase or uppercase (0 or 1 respectively). Also the function returns how many characters were changed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int convert(char *str,int mode){
    int times=0;
   
    while(*str!='\0'){
        if(*str<='z' && *str>='a'){
            if(mode==1){
                *str-=32;
                times++;
            }
        }else if(*str<='Z' && *str>='A'){
            if(mode==0){
                *str+=32;
                times++;
            }  
        }
        str++;
    }
    return times;
}