Indentation really, really helps when you code: it makes it a lot simpler to spot what is going on:
for (i = 0; word[i] != '\0'; ++i)
{
if (word[i] != ' ')
{
str[j] = word[i];
j++;
}
if (word[i] == ' ')
{
w=change(str);
if (w == 1)
{
for (i = 1; i < j - 1; ++i)
{
str[i] = '*';
}
cout<<str<<" ";
j = 0;
}
if (w == 0)
{
cout<<str<<" ";
j = 0;
}
}
}
In this case, it would make it obvious that you are using the same variable for two nested loops...which means that after the second loop, the value of i will always be the same.
And if you'd used the debugger, that would also have made it pretty obvious!