Click here to Skip to main content
15,667,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I originally had my draw function working with no errors, but giving wrong outputs. To test draw() with GDB, I tried making a separate file for draw().
The problem is this runtime error:
~/workspace/pset3/fifteen/ $ ./Untitled2 Untitled2.c:10:15: runtime error: variable length array bound evaluates to non-positive value 0 Untitled2.c:10:18: runtime error: variable length array bound evaluates to non-positive value 0


Thanks a lot,

What I have tried:

C#
include <cs50.h>
include <stdio.h>
include <stdlib.h>
include <unistd.h>
int main(int argc, string argv[]) {
	int d = atoi(argv[0]);
	int board[d][d];
	for (int e = 0; e < d; e++) {
		for (int f = 0; f < d; f++) {
			if (!( ( e == d-1) && ( f == d-1) )) {
				printf("%2d", board[e][f]);
			}
			if ( ( e == d-1) && ( f == d-1) )
			{
				printf("%2c", '_');
			}

		}
		printf("\n");

		printf("\n %i", argc);
	}
}
Posted
Updated 29-Dec-16 9:43am
v2

So use the debugger and find out what the value is: the error message is pretty explicit:
variable length array bound evaluates to non-positive value
So d is zero or negative, which means that atoi returned that. so what is in argv[0] that evaluates to zero or a negative number?

Hint: the first parameter of a C application runtime arguments is the application exe name...
 
Share this answer
 
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900