For working professionals
For fresh graduates
More
Explore C Tutorials: From Begi…
1. Introduction to C Tutorial
2. Addition of Two Numbers in C
3. Anagram Program in C
4. Armstrong Number in C
5. Array in C
6. Array of Pointers in C
7. Array of Structure in C
8. C Program to Find ASCII Value of a Character
9. Assignment Operator in C
10. Binary Search in C
11. Binary to Decimal in C
12. Bitwise Operators in C
13. Boolean in C
14. C Compiler for Mac
15. C Compiler for Windows
16. C Function Call Stack
17. C Language Download
18. Operators in C
19. C/C++ Preprocessors
20. C Program for Bubble Sort
21. C Program for Factorial
22. C Program for Prime Numbers
23. C Program for String Palindrome
24. C Program to Reverse a Number
25. Reverse a String in C
26. C string declaration
27. String Input Output Functions in C
28. Calculator Program in C
29. Call by Value and Call by Reference in C
30. Ceil Function in C
31. Coding Vs. Programming
32. Command Line Arguments in C/C++
33. Comments in C
34. Compilation process in C
35. Conditional Statements in C
36. Conditional operator in the C
37. Constant Pointer in C
38. Constants in C
39. Dangling Pointer in C
40. Data Structures in C
41. Data Types in C
42. Debugging C Program
43. Convert Decimal to Binary in C
44. Define And include in C
45. Difference Between Arguments And Parameters
46. Difference Between Compiler and Interpreter
47. Difference Between If Else and Switch
48. Do While Loop In C
49. Double In C
50. Dynamic Array in C
51. Dynamic Memory Allocation in C
52. Enumeration (or enum) in C
53. Evaluation of Arithmetic Expression
54. Factorial of A Number in C
55. Features of C Language
56. Fibonacci Series Program in C Using Recursion
57. File Handling in C
58. For Loop in C
59. Format Specifiers in C
60. Functions in C
61. Function Pointer in C
62. goto statement in C
63. C Hello World Program
64. Header Files in C
65. Heap Sort in C Program
66. Hello World Program in C
67. History of C Language
68. How to compile a C program in Linux
69. How to Find a Leap Year Using C Programming
70. Identifiers in C
71. If Else Statement in C
72. If Statement in C
73. Implementation of Queue Using Linked List
74. Increment and decrement operators in c
75. Input and Output Functions in C
76. How To Install C Language In Mac
77. Jump Statements in C
78. Lcm of Two Numbers in C
79. Length of an Array in C
80. Library Function in C
81. Linked list in C
82. Logical Operators in C
83. Macros in C
84. Matrix multiplication in C
85. Nested if else statement in C
86. Nested Loop in C
87. One Dimensional Array in C
88. Operator Precedence and Associativity in C
89. Overflow And Underflow in C
90. Palindrome Program in C
91. Pattern Programs in C
92. Pointer to Pointer in C
93. Pointers in C: A Comprehensive Tutorial
94. Pre-increment And Post-increment
95. Prime Number Program in C
96. Program for Linear Search in C
97. Pseudo-Code In C
98. Random Access Files in C
99. Random Number Generator in C
100. Recursion in C
101. Relational Operators in C
102. Simple interest program in C
103. Square Root in C
104. Stack in C
105. Stack Using Linked List in C
106. Static function in C
107. Stdio.h in C
108. Storage Classes in C
109. strcat() in C
110. Strcmp in C
111. Strcpy in C
112. String Comparison in C
113. String Functions in C
114. String Length in C
115. String Pointer in C
116. strlen() in C
117. Structures in C
118. Structure of C Program
119. Switch Case in C
120. C Ternary Operator
121. Tokens in C
122. Toupper Function in C
Now Reading
123. Transpose of a Matrix in C
124. Two Dimensional Array in C
125. Type Casting in C
126. Types of Error in C
127. Unary Operator in C
128. Use of C Language
129. User Defined Functions in C
130. What is Variables in C
131. Is C language case sensitive
132. Fibonacci Series in C
C is a procedural-oriented general-purpose programming language. This high-level language is used to develop computer software, web development, system programming, computer applications, etc. This is a simple and efficient programming language. In C programming some predefined functions are included and stored in the system library. toupper() is one of the most used library functions. Here precise information about the toupper function in C is explained i.e toupper function implementation in C, examples related to toupper function, toupper string in C, return values of toupper() in C, and exceptions of toupper().
The toupper function is a built-in function that is used to perform some specific operation. toupper function in C language is defined in <ctype.h> header file. <ctype.h> header file includes operations related to characters. toupper() in C header file is used to convert the lowercase alphabet to the uppercase alphabet. It excludes some operations including the conversion of uppercase letters, digits, and special characters. To convert the alphabet of a string from uppercase to lowercase, first, each character of the string is traversed in sequence, and then the toupper function is applied to every individual character of the string.
1. If a lowercase alphabet is provided and it needs to be converted to its equivalent uppercase alphabet then toupper() function is used for the conversion
2. The toupper function first considers the ASCII value of the character. After that, it returns the equivalent uppercase character in the form of an integer value.
3. If the inputs to the toupper function consist of the uppercase alphabet, unique character, or digit, then the function returns the original alphabet without any modification.
4. If a string in lowercase is to be converted to uppercase, then all the alphabets of the string are first traversed. Later toupper() is applied to every character separately to convert the alphabet of a string to uppercase.
The syntax of toupper() is
int toupper(int a);
Here the goal is to convert the character ’a’ from lowercase to uppercase. To achieve this toupper function first recognize the ASCII value of the character and then transform the alphabet from lowercase to uppercase.
Example 1: C program to convert a single lowercase character to an uppercase character.
#include <stdio.h>
#include<ctype.h>
Int main()
{
char ch = ‘b’;
printf(“Before implementing toupper function: %c\n”, ch);
ch = toupper(ch);
printf (“After implementing toupper function: %c\n”, ch);
return 0;
}
Output:
Before implementing toupper function: b
After implementing toupper function: B
Algorithm:
1. Initialize the variable ch with the lowercase character ‘b’.
2. The variable is then passed as an argument to toupper() function.
3. Next the converted uppercase character is stored back in the ch variable.
4. Output is printed.
Example 2 : C program to convert a string to uppercase.
#include <stdio.h>
#include<ctype.h>
Int main()
{
char ch[ ] = “good morning everyone @123”;
int i = 0;
while (ch[ i ])
{
putchar (toupper(ch[ i ]));
i ;
}
return 0;
}
Output:
GOOD MORNING EVERYONE @123
Explanation:
1. The string is represented as “good morning everyone @123”.
2. A while loop is used to traverse the string. In this loop toupper function is applied to every character.
3. The lowercase characters are converted to uppercase characters while the symbols and digits remain the same after conversion.
4. Output is printed as GOOD MORNING EVERYONE @123.
Example 3: C program to convert user input to uppercase.
#include <stdio.h>
#include<ctype.h>
Int main()
{
char ch;
printf(“Enter a lowercase character”);
scanf(“%c”, &ch);
ch = toupper(ch);
printf (“After implementing toupper function: %c\n”, ch);
return 0;
}
Output:
Enter a lowercase character r
After implementing toupper function: R
Explanation:
1. The user input is read by scanf() function and the input is stored in character variable ch.
2. The toupper() function is called to convert the lowercase character to an uppercase character.
3. Next the converted uppercase character is stored back in the ch variable.
4. Output is printed.
Example 4: C program to compare characters case-insensitively.
#include <stdio.h>
#include<ctype.h>
Int main()
{
char ch1 = ‘E’;
char ch2 = ‘e’;
if (toupper(ch1)==toupper(ch2))
{
printf(“Both characters are the same (case-insensitive).\n”);
}
else
{
printf(“Characters are not same (case-insensitive).\n”);
}
return 0;
}
Output:
Both characters are the same.
Explanation:
1. The first character ‘E’ is stored in a character variable ch1. The second character ‘e’ is stored in a character variable ch2.
2. First both the characters are converted to uppercase by using the toupper function.
3. The first character ‘E’ is remained as sameE' and the second character ‘e’ is converted to ‘E’.
4. For comparison of characters if a statement is used. It compares if both the characters are equal or not.
5. Output is printed.
Example 5: C program to convert characters of an array to uppercase.
#include <stdio.h>
#include<ctype.h>
Int main()
{
char ch[ ] = “Hello, Everyone”;
int I;
for (i=0; ch[i] != ‘\0’; i );
{
ch[i ] = toupper(ch[ i]);
}
printf(“The string in uppercase is: %s\n”, ch);
return 0;
}
Output:
The string in uppercase is: HELLO, EVERYONE
Explanation:
1. Each character of the ch array is converted to uppercase.
2. For loop iterates each character in the array and the toupper() function is applied to each character.
3. Thus the string is converted to uppercase and the result is printed.
Example 6:
#include <stdio.h>
#include<ctype.h>
Int main()
{
char ch[ ] = “EXCELLENT”;
int i = 0;
while (ch[ i ])
{
putchar (toupper(ch[ i ]));
i ;
}
return 0;
}
Output:
EXCELLENT
Explanation:
The output remains the same as input because the toupper() function does not convert uppercase characters.
Example 7:
#include <stdio.h>
#include<ctype.h>
Int main()
{
char ch[ ] = “123@45#”;
int i = 0;
while (ch[ i ])
{
putchar (toupper(ch[ i ]));
i ;
}
return 0;
}
Output:
123@45#”
Explanation:
The output remains the same as input because the toupper() function does not convert digits and symbols.
1. The input to the toupper function is a single character. Here the character ‘m’ is to be converted to uppercase.
2. The toupper function reads the ASCII value of the character and converts it from lowercase to uppercase.
3. This function is usually operated in conjunction with string manipulation functions to convert a whole string from lowercase to uppercase.
The toupper() returns an uppercase character corresponding to the lowercase character which is given as input to the function.
The exceptions of toupper() in C are listed below.
1. When an uppercase character is given as input to the toupper function then it returns the same original character without any modification.
2. When a special symbol or digit is given as input to the toupper function then it returns the same original character.
The tolower() function converts the uppercase characters into lowercase characters. Syntax of tolower() function is
int tolower(int a);
The difference between toupper() and tolower() functions is that the toupper function is a builtin function that is used to convert the lowercase character to a uppercase character, whereas the tolower() function converts the uppercase characters into lowercase characters.
Detailed information about the use of the toupper function is provided here. The significance of toupper(), the syntax used to define toupper() are explained. The implementation of the toupper function in the C programming language is clearly described. The parameters used in toupper function, return value, and exceptions while using toupper function are also elaborated. Implementation of toupper function in C language is clearly depicted by using various examples. The examples are based on converting a single lowercase character to an uppercase character, converting a string to uppercase, comparison of characters case-insensitively, and conversion of characters of an array to uppercase. The simple yet powerful toupper() function makes C programming easier and more efficient.
1. What is C language?
C is a procedural-oriented general-purpose programming language. This high-level language is used to develop computer software, web development, system programming, computer applications, etc.
2. What is toupper() in C?
The toupper function is a built-in function that is used to convert the lowercase alphabet to the uppercase alphabet.
3. What is <ctype.h>?
<ctype.h> header file includes operations related to characters. toupper function in C language is defined in <ctype.h> header file.
4. What is the syntax of toupper()?
The syntax of toupper() is
int toupper(int a);
Here the goal is to convert the character ’a’ from lowercase to uppercase.
5. How does a toupper() function work?
If a string in lowercase is to be converted to uppercase, then all the alphabets of the string are first traversed. Later toupper() is applied to every character separately to convert the alphabet of a string to uppercase.
6. What are the return Values of toupper() in C?
The toupper() returns an uppercase character corresponding to the lowercase character which is given as input to the function.
7. What are the exceptions of toupper() in C
The exceptions of toupper() in C are listed below.
i) When an uppercase character is given as input to the toupper function then it returns the same original character without any modification.
ii) When a special symbol or digit is given as input to the toupper function then it returns the same original character.
8. What is tolower in c?
The tolower() function converts the uppercase characters into lowercase characters. Syntax of tolower() function is
int tolower(int a);
9. What is the difference between toupper and tolower in C?
The toupper function is a built-in function that is used to convert the lowercase character to the uppercase character, whereas the tolower() function converts the uppercase characters into lowercase characters.
Take a Free C Programming Quiz
Answer quick questions and assess your C programming knowledge
Author
Start Learning For Free
Explore Our Free Software Tutorials and Elevate your Career.
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918045604032
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.