- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert a String to Uppercase in C
Here is the program to convert a string to uppercase in C language,
Example
#include <stdio.h> #include <string.h> int main() { char s[100]; int i; printf("
Enter a string : "); gets(s); for (i = 0; s[i]!='\0'; i++) { if(s[i] >= 'a' && s[i] <= 'z') { s[i] = s[i] -32; } } printf("
String in Upper Case = %s", s); return 0; }
Output
Enter a string : hello world! String in Upper Case = HELLO WORLD!
In the program, the actual code of conversion of string to upper case is present in main() function. An array of char type s[100] is declared which will store the entered string by user.
Then, for loop is used to convert the string into upper case string and if block is used to check that if characters are in lower case then, convert them in upper case by subtracting 32 from their ASCII value.
for (i = 0; s[i]!='\0'; i++) { if(s[i] >= 'a' && s[i] <= 'z') { s[i] = s[i] -32; } }
- Related Articles
- Swift Program to Convert a String to Uppercase
- How to convert a string into uppercase in AngularJS?
- Write a C program to convert uppercase to lowercase letters without using string convert function
- Convert string to lowercase or uppercase in Arduino
- Java program to convert a string to lowercase and uppercase.
- How to convert lowercase letters in string to uppercase in Python?
- C# Program to convert first character uppercase in a sentence
- C Program to convert first character uppercase in a sentence
- How to convert all uppercase letters in string to lowercase in Python?
- For the Hosts Locale how to convert a string to uppercase letters in JavaScript?
- Convert text to uppercase with CSS
- Java Program to convert first character uppercase in a sentence
- How to convert all words of a string or categorical variable in an R data frame to uppercase?
- First uppercase letter in a string (Iterative and Recursive) in C++
- Replacing upperCase and LowerCase in a string - JavaScript

Advertisements