how do i implement a c program that removes all nonalphabets in the given string??

Recommended Answers

All 2 Replies

This can be done through ASCII values capital alphabets ascii values starts from 65-90 and small letters from 97-122 you have to compare the string with these if a string value is not in between assign those values to null or -1

Depends on what you mean by "remove". If you just want to change the nonalphas to something else then use the previous suggestion. Otherwise if you have to move the remaining charactes around to fill up the gaps then you need to create a loop to look at each character. If the character is nonalphabetic then call memmove() to move all remaining characters left one byte. For example if the 7th character is nonascii

char string[] = "Hello 1 World";
memmove(&string[6],&string[7], strlen(&string[7]));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.