Although your code needs a lot of improvement a simple way to work around this is to end the cNewArray string with the escaped zero character:
...
...
...
int endPos = 0;
for ( int i = 0; i < 10; i++ )
{
int j = PosSwitch ( i );
if ( ( cOrigArray [ i ] >= 65 && cOrigArray [ i ] <= 90 ) || ( cOrigArray [ i ] >= 97 && cOrigArray [ i ] <= 122 ) )
{
cNewArray [ j ] = cOrigArray [ i ];
}
else
{
cNewArray [ j ] = ' ';
}
endPos = i;
}
<strong>cNewArray[endPos + 1] = '\0';</strong>
...
...
...
I would also suggest you prompt the user enter 9 letters or less (you have to have in mind the terminal '\0' character), or you could increase the size of each array to 11. :)
mikrosfoititis
Junior Poster in Training
74 posts since Nov 2011
Reputation Points: 18
Solved Threads: 11
Well one sure hint for you is try to think less complex. Things that can get done the simple way, must be done so. You always have to examine your code and ask yourself: "Is there a more simple, cleaner and more direct way to do this?" If so, do it.
Look for example your Absolute function. It can get done as simple as:
unsigned int Absolute(int n) {
if(n<0)
n *= (-1);
return n;
}
mikrosfoititis
Junior Poster in Training
74 posts since Nov 2011
Reputation Points: 18
Solved Threads: 11
No problem :)
Don't worry, all you need is some experience, you're on the right way.
mikrosfoititis
Junior Poster in Training
74 posts since Nov 2011
Reputation Points: 18
Solved Threads: 11