Home » C solved programs » C string programs

C program to remove alphabets from an alphanumeric string



In this C program, we are going to learn how to remove alphabets from a given alphanumeric string? If string contains alphabets and numbers both, this program will remove only alphabets from the string.
Submitted by IncludeHelp, on April 05, 2018

Given a string and we have to remove it all alphabets using C program.

If string contains alphabets and numbers both (or anything with the alphabets), program to check the alphabets, if found then program will remove them from the string.

Example:

    Input:
    String is: "hello123"
    Output:
    Final string is: "123"

    Input:
    String is: "Call 100"
    Output:
    Final string is: "100"

Program to remove all alphabets from given alphanumeric string in C


/* C program to remove all the characters 
* from the alphanumeric string
*/

#include <stdio.h>
#include <string.h>

// This function removes all the chars
// used in the string passed and will leave
// only the alphanumeric characters
int RemoveChars(char *string)
{
	int length=0,i=0,j=0,k=0;

	length = strlen(string);

	for(i=0;i<length;i++)
	{
		for(j=0;j<length;j++)
		{
			if((string[j]>='a' && string[j]<='z') || (string[j]>='A' && string[j]<='Z'))
			{
				for(k=j;k<length;k++)
				{
					string[k] = string[k+1];
				}
				length--;
			}
		}
	}
}

// main function 
int main()
{
	char string[50]={0};

	printf("\nEnter the string : ");
	gets(string);

	// pass the string to the function
	RemoveChars(string);
	printf("Final string is : %s",string);
	return 0;
}

Output

Run 1:
Enter the string : hello123 
Final string is : 123

Run 2:
Enter the string : Call 100 
Final string is : 100





Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.




Comments and Discussions





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.




close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.