How do you remove spaces and special characters from a string?
I couldn't find a single answer while googling. There were a lot related to other languages, but not C. Most of them mentioned the use of regex, which isn't C standard (?).
Removing a simple space is easy:
char str[50] = "Remove The Spaces!!";
Then a simple loop with a if-statement:
if (str[i] != ' ');
Output would be:
RemoveTheSpaces!!
What do I add to the if-statement so it would recognize special characters and remove them?
My definition of special characters:
Characters not included in this list:
A-Z a-z 0-9
chararray. You can replace anawith abbut there's no plain simple way to remove a character index from the array, so you'd still end up with a hole. Although, if its only for printing you could just iterate over the array and if its not in range forascii valuesfor a-zA-Z0-9 then just skip doing anything and go to next character. It's imo often the easiest thing to do when possible. Otherwise you need to copy to a new buffer.