- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 C++ String to Upper Case
Here is the program to convert a string to uppercase in C++ language,
Example
#include<iostream> #include<string.h> using namespace std; int main() { char s[30] = "This_is_string"; int i; for(i=0;i<=strlen(s);i++) { if(s[i]>=97 && s[i]<=122) { s[i]=s[i]-32; } } cout<<"The String in Uppercase = "<<s; return 0; }
Output
Here is the output
The String in Uppercase = THIS_IS_STRING
In the program, the actual code of conversion of string to upper case is present in main() function. An array of char type s[30] is declared which stores the given string.
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;i<=strlen(s);i++) { if(s[i]>=97 && s[i]<=122) { s[i]=s[i]-32; } }
Advertisements
To Continue Learning Please Login
Login with Google