C++ Program to Remove all Characters in a String Except Alphabets

#include <iostream>
using namespace std;
int main() {
   char str[100] = "String@123!!";
   int i, j;
   cout<<"String before modification: "<<str<<endl;
   for(i = 0; str[i] != '\0'; ++i) {
      while(!( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] ==          '\0') {
         for(j = i; str[j] != '\0'; ++j) {
            str[j] = str[j+1];
         }
      }
   }
   cout<<"String after modification: "<<str;
   return 0;
}

OUTPUT:

String before modification: String@123!!
String after modification: String

Leave a Comment