C Online Compiler
Example: Remove Non-Alphabets (In-Place) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Remove Non-Alphabets (In-Place) #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 myString[] = "H3ll0, W0rld! 123"; int readPtr, writePtr; // Step 1: Initialize writePtr to 0, which will point to the next available position for a valid character writePtr = 0; // Step 2: Iterate through the string using readPtr for (readPtr = 0; myString[readPtr] != '\0'; readPtr++) { // Step 3: Check if the character is an alphabet if (isalpha(myString[readPtr])) { // Step 4: If it's an alphabet, copy it to the writePtr position myString[writePtr] = myString[readPtr]; writePtr++; // Move writePtr forward } } // Step 5: Null-terminate the modified string at the writePtr position myString[writePtr] = '\0'; printf("Original string (after modification): %s\n", myString); return 0; }
Output
Clear
ADVERTISEMENTS