C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Strings in C

Remove All Digits from String

C Program: Remove All Digits from String

C

#include <stdio.h>

 

int main() {

    char str[200], result[200];

    int i, j = 0;

 

    // Input string

    printf("Enter a string: ");

    fgets(str, sizeof(str), stdin);

 

    // Remove digits

    for (i = 0; str[i] != '\0'; i++) {

        if (!(str[i] >= '0' && str[i] <= '9')) {  // Skip digits

            result[j++] = str[i];

        }

    }

 

    result[j] = '\0';  // Null terminate the result string

 

    printf("String after removing digits: %s", result);

 

    return 0;

}

Output

 
OUTPUT :
Enter a string: IT123Developer2025
String after removing digits: ITDeveloper

Explanation

  • The program reads a string using fgets().
  • It loops through each character:
    • If the character is not a digit ('0''9'), it is copied to result.
    • Digits are skipped.
  • The final result string contains only non-numeric characters.