I'm trying to create a function that takes in an array of characters with a string, for example ENCRYPT THIS MESSAGE. I have read a few other topics on this site about people doing the same thing but none of the answers worked for me. So I tried to implement a function that takes in the character array and returns a new character array without spaces or punctuation. Here is the function I have so far:
1 2 3 4 5 6 7 8 9
void RemovePunct(char old_String[], char new_String[]){
for (int i = 0; i != 50; i++)
{
if(isspace(old_String[i])==true) continue;
if(ispunct(old_String[i])==true) continue;
if(isalnum(old_String[i])) new_String[i] = old_String[i];
}
return;
}
When I run the example string through this function it returns "ENCRYPTSTHIS▒MESSAGEE", "ENCRYPTTHIS▒MESSAGE", "ENCRYPTTHIS▒MESSAGEE", or some similar variation with extra letters or special characters. Sometimes it removes one space successfully but the other space is always a letter or some weird character. Anyone have any ideas what is wrong with this function or how to make it work successfully? Thanks in advanced for any help.