Jump to content

so i determined that the declaration of my 2D array is the problem (commented everything out, left only the variables and the commented out the 2d array, and all was good), any ideas why the mistake?

string mode[1000], mode1 [1000], mode2[1000];int startX[1000],startY[1000], endX[1000],endY[1000];int beatNeighbour[1000][1000];

Console window: http://imgur.com/yKP8nFk

EDIT: with that "return" i cannot output anything to console, even a simple cout<<"a";

EDIT 2: how to allocate memory for my 2d array? (when declaring int beatNeighbour [1000] [100], no error)

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/
Share on other sites

Link to post
Share on other sites

so i determined that the declaration of my 2D array is the problem (commented everything out, left only the variables and the commented out the 2d array, and all was good), any ideas why the mistake?

string mode[1000], mode1 [1000], mode2[1000];int startX[1000],startY[1000], endX[1000],endY[1000];int beatNeighbour[1000][1000];

Console window: http://imgur.com/yKP8nFk

EDIT: with that "return" i cannot output anything to console, even a simple cout<<"a";

there's a space in your mode1 [1000] declaration?

Home is where the heart my desktop is.

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6727279
Share on other sites

Link to post
Share on other sites

there's a space in your mode1 [1000] declaration?

it could be mode1           [1000]             ;

white space is not an issue

int beatNeighbour[1000][1000];

this makes the error

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6727291
Share on other sites

Link to post
Share on other sites

it could be mode1           [1000]             ;

white space is not an issue

int beatNeighbour[1000][1000];

this makes the error

indeed it doesn't, I've never declared an array with whitespace between the name and dimension because I thought it matters :P

In which case, sorry i have no idea why it doesn't work, I couldn't see anything wrong with those declarations

Home is where the heart my desktop is.

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6727327
Share on other sites

Link to post
Share on other sites

Maybe it's just that you're allocating too much on the stack, which isn't all that big.

I don't know the stack size, it depends on the OS and compiler(-options), but one million ints is several MB, which is more than usual.

You could try to use dynamic variables, as the heap is a lot bigger than the stack.

Edit: Google said that the default stack size on Visual Studio is 1 MB, so if that's what you're using, that's the problem. But I'm pretty sure you can configure the stack size. I know on Linux that stack size is a variable you can set in bash and not a compiler option. I'm not sure about Windows.

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6727408
Share on other sites

Link to post
Share on other sites

Maybe it's just that you're allocating too much on the stack, which isn't all that big.

I don't know the stack size, it depends on the OS and compiler(-options), but one million ints is several MB, which is more than usual.

You could try to use dynamic variables, as the heap is a lot bigger than the stack.

i thought that that might be an issue, but i dont know how to do that

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6727419
Share on other sites

Link to post
Share on other sites

after doing the third option:

int **beatNeighbour= new int *[1000];    for(size_t i=0; i<1000; i++)        beatNeighbour[i]=new int [1000];    for(size_t i=1000; i>0; i)    {        delete[] beatNeighbour[i];    }    delete[] beatNeighbour;

 I get this error:

cannot convert 'int**' to 'int (*)[1000]' for argument '7' to 'void duomenys(std::string*, std::string*, int*, int*, int*, int*, int (*)[1000], int&)

in my fucntion:

void duomenys(string mode1[], string mode2[], int startX[], int startY[], int endX[], int endY[],int beatNeighbour[][1000], int &counter);

(error in main):

    duomenys(mode1, mode2,startX,startY,endX,endY,beatNeighbour,counter);// error here

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6727543
Share on other sites

Link to post
Share on other sites

 

 I get this error:

cannot convert 'int**' to 'int (*)[1000]' for argument '7' to 'void duomenys(std::string*, std::string*, int*, int*, int*, int*, int (*)[1000], int&)

in my fucntion:

void duomenys(string mode1[], string mode2[], int startX[], int startY[], int endX[], int endY[],int beatNeighbour[][1000], int &counter);

what happens if you change 'int beatNeighbour[][1000]' to 'int **beatNeighbour'

I remain,  

msevilgenius

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6728397
Share on other sites

Link to post
Share on other sites

@msevilgenius

 

cannot open output file C:\...\main.exe Permission denied.

 

BTW, do i use my 2D array as normal array?

 

EDIT: googled, had to end the process with task manager. when lanched it displays black console window without ANY text

i5-4690k, R9 380 4gb, 8gb-1600MHz ram, corsair vs 550w, astrock h97m anniversary.

 

Link to comment
https://linustechtips.com/topic/503904-2d-array-error-c/#findComment-6728450
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×