Prog error: for replacing spaces with "%20"
<p>below is the prog i am compiling for replacing spaces with "%20" but when I run it output window shows blank and a message "arrays5.exe has occurred a prob"</p>

<pre><code>#include &lt;iostream&gt;
#include&lt;cstring&gt;

using namespace std;

void method(char str[], int len)               //replaces spaces with "%20"
{

    int spaces, newlen,i;

    for (i=0;i&lt;len;i++)
        if(str[i]==' ') spaces++;
    newlen=len+spaces*2;
    str[newlen]=0;
    for (i=len-1;i&gt;=0;i--)
    {
        if(str[i]==' ')
        {
            str[newlen-1]='0';
            str[newlen-2]='2';
            str[newlen-3]='%';
            newlen=newlen-3;
        }
        else
        {
            str[newlen-1]=str[i];
            newlen=newlen-1;
        }
    }
}
int main()
{
    char str[20]="sa h ";
    method(str,5);
    cout &lt;&lt;str&lt;&lt;endl;
    return 0;
}
</code></pre>

<p>Please help me finding the error.Thanks</p>
