C Online Compiler
Example: Remove Non-Alphabets (Temporary String) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Remove Non-Alphabets (Temporary String) #include <stdio.h> #include <string.h> // For strlen (not strictly needed for this loop, but good for general string ops) #include <ctype.h> // For isalpha int main() { char originalString[] = "H3ll0, W0rld! 123"; char cleanString[100]; // Assuming the cleaned string won't exceed 99 chars + null terminator int i, j; // Step 1: Initialize an index for the cleanString j = 0; // Step 2: Iterate through the original string for (i = 0; originalString[i] != '\0'; i++) { // Step 3: Check if the character is an alphabet using isalpha() if (isalpha(originalString[i])) { // Step 4: If it's an alphabet, copy it to the cleanString cleanString[j] = originalString[i]; j++; // Increment index for cleanString } } // Step 5: Null-terminate the cleanString to make it a valid C string cleanString[j] = '\0'; printf("Original string: %s\n", originalString); printf("Cleaned string: %s\n", cleanString); return 0; }
Output
Clear
ADVERTISEMENTS