In my version of the game "hangman" i am getting an error in a function
<pre><code>#include &lt;iostream&gt;
#include "randword.h"
#include &lt;fstream&gt;
#include &lt;time.h&gt;
#include &lt;cstdlib&gt;

using namespace std;

bool hangmachine(char a[],string randi,char v){   //the Problem is in this function

bool retus=0;
for (int cc=0;cc&lt;randi.length();cc++){
if(v==randi[cc]){
retus=1;
char a[cc]=v;     //Error: variable-sized object 'a' may not be initialized.....
}
}
return retus;
}


int main()
{
InitDictionary();
string tixaio=Randomword();
int m = tixaio.length();
int guesses=8;
char guess;
char *charptr= new char[m];


for(int aa=0;aa&lt;m;aa++){
charptr[aa]='-';

}
charptr[m]='\0';

cout &lt;&lt; "The word now looks like this: "&lt;&lt;charptr;
cout&lt;&lt; endl;

while (guesses&gt;0){

    cout&lt;&lt;"Give me your guess: ";
    cin&gt;&gt; guess;
    cout&lt;&lt;endl;
    if(hangmachine(charptr,tixaio,guess)){
        cout &lt;&lt;"the string has now become"&lt;&lt;charptr&lt;&lt;endl;
        cout &lt;&lt;"You have "&lt;&lt; guesses&lt;&lt;" remaining guesses"&lt;&lt; endl;

    }

    else{
    guesses-=1;
    cout&lt;&lt;"you made a wrong guess .Now you have "&lt;&lt; guesses&lt;&lt;" remaining tries"&lt;&lt; endl;

    }


}


}
</code></pre>

<p>The problem seems to be that i am not passing the dynamically allocated array to the function in the right way. I have made comments to the line i am getting this error.But the compiler doesn't give me any error when i call the function in the main() so it must be something wrong in the way i define this function.Any help would be appreciated. </p>

<p>Sometimes i feel so stupid......Sorry for not being carefull enough.</p>
