Open In App

tolower() Function in C

Last Updated : 06 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

tolower() function in C is used to convert the uppercase alphabet to the lowercase alphabet. It does not affect characters other than uppercase characters. It is defined in the <ctype.h> header file in C.

Syntax

The syntax of tolower() function is:

int tolower(int c);

Parameter

  • This function takes a character as a parameter.

Return Value

  • It returns the ASCII value corresponding to the lowercase of the character passed as the argument.

Examples of tolower() Function

Example 1

The below C program demonstrates the tolower() function.

C




// C program to demonstrate
// example of tolower() function.
#include <ctype.h>
#include <stdio.h>
 
int main()
{
 
    // convert 'M' to lowercase
    char ch = tolower('M');
 
    // Printing the lowercase letter
    printf("%c", ch);
 
    return 0;
}


Output

m

Example 2

The below code converts all uppercase letters in the string to their lowercase equivalents, while leaving other characters unchanged.

C




// C program to demonstrate
// example of tolower() function.
#include <ctype.h>
#include <stdio.h>
 
int main()
{
 
    char s[] = "Code_in_C_@0123";
 
    // This will just convert
    // uppercase letters in string
    // to lowercase. Other characters
    // will remain unaffected.
    for (int i = 0; i < strlen(s); i++) {
        s[i] = tolower(s[i]);
    }
 
    // Printing the output
    printf("%s", s);
 
    return 0;
}


Output

code_in_c_@0123


Similar Reads

C Function Arguments and Function Return Values
Prerequisite: Functions in C A function in C can be called either with arguments or without arguments. These functions may or may not return values to the calling functions. All C functions can be called either with arguments or without arguments in a C program. Also, they may or may not return any values. Hence the function prototype of a function
6 min read
Write a one line C function to round floating point numbers
Algorithm: roundNo(num) 1. If num is positive then add 0.5. 2. Else subtract 0.5. 3. Type cast the result to int and return. Example: num = 1.67, (int) num + 0.5 = (int)2.17 = 2 num = -1.67, (int) num - 0.5 = -(int)2.17 = -2 Implementation: /* Program for rounding floating point numbers */ # include&lt;stdio.h&gt; int roundNo(float num) { return nu
1 min read
Does C support function overloading?
First of all, what is function overloading? Function overloading is a feature of a programming language that allows one to have many functions with same name but with different signatures. This feature is present in most of the Object Oriented Languages such as C++ and Java. But C doesn't support this feature not because of OOP, but rather because
2 min read
How can I return multiple values from a function?
We all know that a function in C can return only one value. So how do we achieve the purpose of returning multiple values. Well, first take a look at the declaration of a function. int foo(int arg1, int arg2); So we can notice here that our interface to the function is through arguments and return value only. (Unless we talk about modifying the glo
2 min read
How to declare a pointer to a function?
While a pointer to a variable or an object is used to access them indirectly, a pointer to a function is used to invoke a function indirectly. Well, we assume that you know what it means by a pointer in C. So how do we create a pointer to an integer in C? Huh..it is pretty simple... int *ptrInteger; /*We have put a * operator between int and ptrInt
2 min read
Can We Call an Undeclared Function in C++?
Calling an undeclared function is a poor style in C (See this) and illegal in C++and so is passing arguments to a function using a declaration that doesn't list argument types.If we call an undeclared function in C and compile it, it works without any error. But, if we call an undeclared function in C++, it doesn't compile and generates errors. In
2 min read
What is evaluation order of function parameters in C?
It is compiler dependent in C. It is never safe to depend on the order of evaluation of side effects. For example, a function call like below may very well behave differently from one compiler to another: void func (int, int); int i = 2; func (i++, i++); There is no guarantee (in either the C or the C++ standard language definitions) that the incre
1 min read
Can We Use Function on Left Side of an Expression in C and C++?
In C, it is not possible to have function names on the left side of an expression, but it's possible in C++. How can we use the function on the left side of an expression in C++? In C++, only the functions which return some reference variables can be used on the left side of an expression. The reference works in a similar way to pointers, so whenev
1 min read
C++ | Function Overloading and Default Arguments | Question 5
Which of the following in Object Oriented Programming is supported by Function overloading and default arguments features of C++. (A) Inheritance (B) Polymorphism (C) Encapsulation (D) None of the above Answer: (B) Explanation: Both of the features allow one function name to work for different parameter. Quiz of this Question
1 min read
C++ | Function Overloading and Default Arguments | Question 2
Output? #include&lt;iostream&gt; using namespace std; int fun(int x = 0, int y = 0, int z) { return (x + y + z); } int main() { cout &lt;&lt; fun(10); return 0; } (A) 10 (B) 0 (C) 20 (D) Compiler Error Answer: (D) Explanation: All default arguments must be the rightmost arguments. The following program works fine and produces 10 as output. #include
1 min read
C++ | Function Overloading and Default Arguments | Question 3
Which of the following overloaded functions are NOT allowed in C++? 1) Function declarations that differ only in the return type int fun(int x, int y); void fun(int x, int y); 2) Functions that differ only by static keyword in return type int fun(int x, int y); static int fun(int x, int y); 3)Parameter declarations that differ only in a pointer * v
1 min read
C++ | Function Overloading and Default Arguments | Question 4
Predict the output of following C++ program. include&lt;iostream&gt; using namespace std; class Test { protected: int x; public: Test (int i):x(i) { } void fun() const { cout &lt;&lt; &quot;fun() const &quot; &lt;&lt; endl; } void fun() { cout &lt;&lt; &quot;fun() &quot; &lt;&lt; endl; } }; int main() { Test t1 (10); const Test t2 (20); t1.fun(); t
1 min read
C++ | Function Overloading and Default Arguments | Question 5
Output of following program? #include &lt;iostream&gt; using namespace std; int fun(int=0, int = 0); int main() { cout &lt;&lt; fun(5); return 0; } int fun(int x, int y) { return (x+y); } (A) Compiler Error (B) 5 (C) 0 (D) 10 Answer: (B) Explanation: The statement "int fun(int=0, int=0)" is declaration of a function that takes two arguments with de
1 min read
wcscspn() function in C/C++
The wcscspn() function in C/C++ searches the first occurrence of a wide character of string_2 in the given wide string_1. It returns the number of wide characters before the first occurrence of that wide character . The search includes the terminating null wide characters. Therefore, the function will return the length of string_1 if none of the ch
2 min read
C Library Function - difftime()
The difftime() is a C Library function that returns the difference in time, in seconds(i.e. ending time - starting time). It takes two parameters of type time_t and computes the time difference in seconds. The difftime() function is defined inside the &lt;time.h&gt; header file. Syntax The syntax of difftime() function is as follows: double difftim
1 min read
Count the number of objects using Static member function
Prerequisite : Static variables , Static Functions Write a program to design a class having static member function named showcount() which has the property of displaying the number of objects created of the class. Explanation: In this program we are simply explaining the approach of static member function. We can define class members and member fun
2 min read
C program to copy string without using strcpy() function
strcpy is a C standard library function that copies a string from one location to another. It is defined in the string.h header file. We can use the inbuilt strcpy() function to copy one string to another but here, this program copies the content of one string to another manually without using strcpy() function. Methods to Copy String without using
3 min read
mbtowc function in C
Convert multibyte sequence to wide character. The multibyte character pointed by pmb is converted to a value of type wchar_t and stored at the location pointed by pwc. The function returns the length in bytes of the multibyte character. mbtowc has its own internal shift state, which is altered as necessary only by calls to this function. A call to
2 min read
isxdigit() function in C Language
isxdigit() function in C programming language checks that whether the given character is hexadecimal or not. isxdigit() function is defined in ctype.h header file. Hexadecimal equivalent of Decimal Numbers: Hexadecimal: 0 1 2 3 4 5 6 7 8 9 A B C D E F Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Syntax: char isxdigit( char x); Examples: Input : A
2 min read
isupper() function in C Language
isupper() function in C programming checks whether the given character is upper case or not. isupper() function is defined in ctype.h header file. Syntax : int isupper ( int x ); Examples: Input: A Output: Entered character is uppercase character Input: a Output: Entered character is not uppercase character Input: 1 Output: Entered character is not
2 min read
isalnum() function in C Language
isalnum() function in C programming language checks whether the given character is alphanumeric or not. isalnum() function defined in ctype.h header file. Alphanumeric: A character that is either a letter or a number. Syntax: int isalnum(int x); Examples: Input : 1 Output : Entered character is alphanumeric Input : A Output : Entered character is a
2 min read
wcstof function in C library
The wcstof() functions convert the initial portion of the wide-character string pointed to by str to a float point value. The str parameter points to a sequence of characters that can be interpreted as a numeric floating-point value. These functions stop reading the string at the first character that it cannot recognize as part of a number i.e. if
2 min read
pieslice() function in C
pieslice() draws and fills a pie slice with center at (x, y) and given radius r. The slice travels from s_angle to e_angle which are starting and ending angles for the pie slice. The angles for pie-slice are given in degrees and are measured counterclockwise. Syntax : void pieslice(int x, int y, int s_angle, int e_angle, int r); where, (x, y) is ce
2 min read
arc function in C
The header file graphics.h contains arc() function which draws an arc with center at (x, y) and given radius. start_angle is the starting point of angle and end_angle is the ending point of the angle. The value of the angle can vary from 0 to 360 degree. Syntax : void arc(int x, int y, int start_angle, int end_angle, int radius); where, (x, y) is t
2 min read
settextstyle function in C
The header file graphics.h contains settextstyle() function which is used to change the way in which text appears. Using it we can modify the size of text, change direction of text and change the font of text. Syntax : void settextstyle(int font, int direction, int font_size); where, font argument specifies the font of text, Direction can be HORIZ_
2 min read
grapherrormsg() function in C
The header file graphics.h contains grapherrormsg() function which returns an error message string. Syntax : char *grapherrormsg( int errorcode ); where, errorcode: code for the respective error Illustration of the grapherrormsg() : In the below program, gd = DETECT is not written and thus program must throw an error. Below is the implementation of
1 min read
textwidth() function in C
The header file graphics.h contains textwidth () function which returns the width of input string in pixels. Syntax : int textwidth(char *string); Example : Input : string = "Hello Geek ! Have a good day." Output : Below is the implementation of textwidth() function. // C Implementation for textwidth() #include &lt;graphics.h&gt; #include &lt;stdio
1 min read
textheight() function in C
The header file graphics.h contains textheight() function which returns the height of input string in pixels. Syntax : int textheight(char *string); Example : Input : string = "Hello Geek ! Have a good day." Output : Below is the implementation of textheight() function. // C Implementation for textheight() #include &lt;graphics.h&gt; #include &lt;s
1 min read
imagesize() function in C
The header file graphics.h contains imagesize() function which returns the number of bytes required to store a bit-image. Syntax : unsigned int imagesize(int left, int top, int right, int bottom); where, left, top, right, and bottom define the area of the screen in which image is stored. Below is the implementation of imagesize() function. // C Imp
2 min read
setcolor function in C
The header file graphics.h contains setcolor() function which is used to set the current drawing color to the new color. Syntax : void setcolor(int color); Explanation : In Graphics, each color is assigned a number. Total number of colors available are 16. Number of available colors depends on current graphics mode and driver. For example, setcolor
2 min read