-->

Friday, 10 March 2017

Example: Remove Characters in String Except Alphabets
#include<stdio.h>

int main()
{
    char line[150];
    int i, j;
    printf("Enter a string: ");
    gets(line);

    for(i = 0; line[i] != '\0'; ++i)
    {
        while (!( (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') || line[i] == '\0') )
        {
            for(j = i; line[j] != '\0'; ++j)
            {
                line[j] = line[j+1];
            }
            line[j] = '\0';
        }
    }
    printf("Output String: ");
    puts(line);
    return 0;
}


Output

Enter a string: ku3tt4ySe@lva
Output String: kuttyselva
This program takes a string from the user and stored in the variable line.

The, within the for loop, each character in the string is checked if it's an alphabet or not.

If any character inside a string is not a alphabet, all characters after it including the null character is shifted by 1 position to the left.

keep calm and say bujuku bujuku.

0 comments:

Post a Comment

Start Work With Me

Contact Us
KUTTY SELVA
+91 7708139984
Madurai,Tamilnadu