Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:54:13+00:00 2026-05-24T00:54:13+00:00

#include <iostream> #include randword.h #include <fstream> #include <time.h> #include <cstdlib> using namespace std; bool

  • 0
#include <iostream>
#include "randword.h"
#include <fstream>
#include <time.h>
#include <cstdlib>

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<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<m;aa++){
charptr[aa]='-';

}
charptr[m]='\0';

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

while (guesses>0){

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

    }

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

    }


}


}

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.

Sometimes i feel so stupid……Sorry for not being carefull enough.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:54:14+00:00Added an answer on May 24, 2026 at 12:54 am

    This line:

    char a[cc]=v;
    

    is a variable declaration, which doesn’t even compile, as the array size should be fixed at compilation time, that is, it has to be either a number or a const integer. It isn’t, so you gcc tries to create a variable length array, but then you try to initialize it which will fail.

    You just want to set a value in the array:

    a[cc]=v;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> #include <string.h> using namespace std; int main() { char firstname[] = Alfred;
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
#include iostream #include string using namespace std; #define AA(bb) \ string(::##bb); int main (int
#include <iostream> #include <string> #include <unordered_map> using namespace std; int main() { unordered_map< int,
#include <iostream> using namespace std; int main() { double u = 0; double w
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
#include iostream #include vector using namespace std; const vector<int>& Getv() { vector<int> w(10); w[0]=10;
#include <iostream> #include <iomanip> using namespace std; double distance(double, double); int main () {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.