- 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
Toggle all characters in the string in C++
This program translates the characters of a string into uppercase. However, this task can be easily achieved by using the toUpper() method of the c++ class library. But in this program, we perform this by calculating the ASCII value of characters in uppercase. The Algorithm is as follows;
Algorithm
START Step-1: Declare the array of char Step-2: Check ASCII value of uppercase characters which must grater than A and lesser than Z Step-3: Check ASCII value of lower characters which must grater than A and lesser than Z END
The toggleChar() method gets the array of characters as an input. Then, traverse through the loop to ensure whether the entered character ASCII value is in the between of the A to Z or not, as following;
Example
#include<iostream> using namespace std; void toggleChars(char str[]){ for (int i=0; str[i]!='\0'; i++){ if (str[i]>='A' && str[i]<='Z') str[i] = str[i] + 'a' - 'A'; else if (str[i]>='a' && str[i]<='z') str[i] = str[i] + 'A' - 'a'; } } int main(){ char str[] = "ajay@kumar#Yadav"; cout << "String before toggle::" << str << endl; toggleChars(str); cout << "String after toggle::" << str; return 0; }
The supplied string has almost all characters in lower case which will be converted in uppercase as following;
Output
String before toggle::ajay@kumar#Yadav String after toggle::AJAY@KUMAR#yADAV
- Related Articles
- Print all distinct characters of a string in order in C++
- C++ Program to Remove all Characters in a String Except Alphabets
- Count Unique Characters of All Substrings of a Given String in C++
- Python - Check If All the Characters in a String Are Alphanumeric?
- Find the smallest window in a string containing all characters of another string in Python
- How to determine if the string has all unique characters using C#?
- Remove all non-alphabetical characters of a String in Java?
- Python program to find all duplicate characters in a string
- Java program to find all duplicate characters in a string
- Removing all non-alphabetic characters from a string in JavaScript
- C# program to determine if a string has all unique characters
- Swapping Characters of a String in C#
- Write a java program reverse tOGGLE each word in the string?
- MySQL Query to remove all characters after last comma in string?
- Replace all characters in a string except the ones that exist in an array JavaScript

Advertisements