C Program to Remove all Characters in a String Except Alphabets - Source Code, Output & Execution Flow

C Program to Remove all Characters in a String Except Alphabets

This tutorial explains c program to remove all characters in a string except alphabets with C source code, sample output, and step-by-step execution flow.

#include <stdio.h>
int main() {
    char str[] = "P2r@o!g#r4a%m", result[50];
    int i, j = 0;
    for (i = 0; str[i]; i++)
        if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z')) result[j++] = str[i];
    result[j] = '';
    printf("Alphabets only: %s
", result);
    return 0;
}
Alphabets only: Program

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.