How to implement the tolower() function to converts character to lowercase in C

1 Answer

0 votes
#include <stdio.h>

int my_tolower(int c);

int main(void)
{
    int i = 0;
    char str[] = "ABCD";
	
    while( str[i] ) 
    {
      str[i] = my_tolower(str[i]);
      i++;
    }
    puts(str);

    return 0;
}

int my_tolower(int c) 
{ 
    if (c >= 'A' && c <= 'Z') 
        return c + 'a' - 'A'; 
    else 
        return c; 
} 

  
/*
  
run:
  
abcd

*/



answered Nov 5, 2015 by avibootz
edited Nov 6, 2015 by avibootz

Related questions

...