Remove white space problem
Hi, I am new to programming and I am trying to figure out what I am doing wrong with my code. I want to be able to remove spaces from a string. Using my code I get ! in places where I have white space instead of moving the next character to the position of the white space. Can anyone tell me what I am missing?
Code:
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <math.h>
#include <string.h>
int main()
{
const int MAXCHARS = 71;
char temp[MAXCHARS];
char words[MAXCHARS] = "M y na me is J o hn ";
int i;
for(i=0; i < MAXCHARS; i++)
{
for(i=0; i < MAXCHARS; i++)
{
if (words[i] == 32)
{
temp[i] = words[i] + 1 ;
}
else
temp[i] = words[i];
}
cout << temp << endl;
getch();
}
return 0;
}