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

  • SEARCH
  • Home
  • 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 7725007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:49:52+00:00 2026-06-01T04:49:52+00:00

I am doing a minesweeper program for school, but i keep getting this error

  • 0

I am doing a minesweeper program for school, but i keep getting this error on my code

cannot allocate an array of constant size 0

I do not know why this is happening; I am not allocating the size — I am setting that on 0. Another problem is, how can I read my input char by char, so I can save it in my array?

As you can see below, I am using an input and output. I comented my input and my ouput so you guys can see what im using for this program. I want to read char by char so I can save all the map on the array.

I am using MSVC++2010.

freopen("input.txt","rt",stdin);
//4 4
//*...
//....
//.*..
//....
//3 5
//**...
//.....
//.*...
//0 0


freopen("output.txt","wt",stdout);

/*Field #1:
*100
2210
1*10
1110

Field #2:
**100
33200
1*100*/
int n=-1;
int m=-1;
int cont =0;
while(n!=0 && m!=0)
{
    scanf("%d %d",&n,&m);
    int VMatriz[n][m]={0};
    int Mapa[n][m]={0};


    if (n==0 && m==0)
        break;
    cont++;
    printf("Field #%d",cont);


    for (int i=0;i<n;i++)
    {   printf("/n");
        for (int j=0;j<m;j++)
        {

            scanf("%d ",&Mapa[i][j]);

            if (Mapa[i][j]=='*')
                {
                    if (j-1>=0)
                        VMatriz[i][j-1]++;
                    if (j+1<m)
                        VMatriz[i][j+1]++;
                    if (i-1>=0)
                        VMatriz[i-1][j]++;
                    if (i+1<m)
                        VMatriz[i+1][j]++;

                    if (j-1>=0 && i-1>0)
                        VMatriz[i-1][j-1]++;
                    if (j-1>=0 && i+1<m)
                        VMatriz[i+1][j-1]++;
                    if (j+1<m && i-1>0)
                        VMatriz[i-1][j+1]++;
                    if (j+1<m && i+1<m)
                        VMatriz[i+1][j+1]++;

                    VMatriz[i][j]='*';

                printf("%d",VMatriz[i][j]);


                }

        }   

    }
    printf("/n");


}
return 0;

}

  • 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-06-01T04:49:53+00:00Added an answer on June 1, 2026 at 4:49 am
    int VMatriz[n][m]={0};
    

    This is illegal. As is this simpler version;

    int n = 10;
    int x[n]; // C2057
    

    However…

    int x[10]; // ok!
    

    The error you actually care about here is this one, not the “cannot allocate an array of constant size 0” error.

    error C2057: expected constant expression

    You cannot allocate an array of unknown size with automatic storage duration in C++. If you want a variable sized array then you need to dynamically allocate it (or, better yet; just use a vector).

    Note that there is a gcc extension to allow this, but not in VS (and it is not standard C++. It was submitted for C++ 11, but ultimately declined.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing some testing but cannot fabricate debug environment so maybe someone can answer this.
Doing this works in IE7: <a href= target=_blank>Link</a> But in IE8 it open a
Doing a code review I've stumbled over GWM in Java-Spring-GWT web-application. As this product
Doing some refactoring in some legacy code I've found in a project. This is
Doing this in a console program: object x = new string(new char[0]); If one
Doing this: s = hello s[0] outputs the character code value 104 . What
Doing a recent build, I ran Django's syncdb, and I'm getting the error: Traceback
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing code analysis of the project and get the message Reference-counted object is used
Doing a simple Squeryl database lookup, but trying to exclude a value. I've tried:

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.