Hi. I am a C++ programming Newbie working on a homework (ahead of schedule, yes!!!) for my C++ intro class. I am using MS Visual C++ in Windows 7 for class but I use g++ in Ubuntu 12.04 at home.
My question is that I need to write a function that copies a string array to another string array while it removes the spaces and punctuation from a string array. I have the code written and compiled (MS Visual C++) but am getting an error code when running the program. After receiving input and outputting it back on the screen (see below), a dialog box opens which says "Debug Assertion Failed" and "Expression:(unsigned)(c + 1) <=256
I'm lost and sorry if this is a silly newbie mistake... I also have a screenshot of the dialog box if someone can tell me how to post it. Thanks in advance!!!
Enter some input: Hi Cplusplus forum
Before remove, contents of the array:
----------------------
Hi Cplusplus forum
new_String[(i - number)] = old_String[i]; //Add the character to new_String[] at 'i - number'.
int number = 0;
number = number + 1;
You're trying to use number before declaring it. Also note that if you declare number within the if statement, it will go out of scope and then be reinitialized to 0 each time the if statement is reached (i.e. every time the loop runs), so you may want to rethink where you put that.
Thanks guys... so I rewrote void RemovePunct() but still have the same error. Here is what I have so far...
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void RemovePunct(char old_String[], char new_String[])
{
int number = 0;
for (int i = 0; i != Size; i++)
{
if (isalnum(old_String[i]))//If current character is alpha-numeric
{
new_String[(i - number)] = old_String[i]; //Add the character to new_String[] at 'i - number'.
number = number + 1;
}
}
return;
}
So while number would certainly have been a problem, it is not the problem