Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ programming code to remove all characters from string except alphabets

#include 
using namespace std;
int main()
{
    //Initializing variable.
    char str[100];
    int i, j;
    
    //Accepting input.
    cout<<"Enter a string : ";
    gets(str);

    //Iterating each character and removing non alphabetical characters.
    for(i = 0; str[i] != ''; ++i)
    {
        while (!( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '') )
        {
            for(j = i; str[j] != ''; ++j)
            {
                str[j] = str[j+1];
            }
            str[j] = ''; 
        }
    }
    //Printing output.
    cout<<"After removing non alphabetical characters the string is :";
    puts(str);
    return 0;
}
Source by prepinsta.com #
 
PREVIOUS NEXT
Tagged: #programming #code #remove #characters #string #alphabets
ADD COMMENT
Topic
Name
2+8 =