Answer the question
In order to leave comments, you need to log in
How to fix "expression must have pointer-to-object type" error?
I am making a multi-file C++ project with 2 .cpp files and 1 .h file (direct.h). Here is the main function:
#include <iostream>
#include <direct.h>
using namespace std;
int direct(const int rows, const int cols, int ARR);
int main()
{
const int rows = 9;
const int cols = 9;
int ARR[rows][cols];
direct(const int rows, const int cols, int ARR);
}
int direct(const int rows, const int cols, int ARR)
{
int val;
// Initialize the array to 0 values
for (int i = 0; i < rows;i++)
{
for (int j = 0; j < cols;j++)
{
val = 0;
}
}
// Use symbols for directions
enum dir
{
left = 0,
down,
up,
right,
}
dir = left;
// Define the starting point and starting value
int x = rows / 2;
int y = cols / 2;
int val = 1;
// A flag to know when to stop
bool stop = false;
// Start
for (;;)
{
ARR[x][y] = val++;
switch (dir)
{
case left:
y -= 1;
if (y < 0) stop = true;
else if (ARR[x + 1][y] == 0) dir = down;
break;
case down:
x += 1;
if (x > rows) stop = true;
else if (ARR[x][y + 1] == 0) dir = right;
break;
case right:
y += 1;
if (y >= rows) stop = true;
else if (ARR[x - 1][y] == 0) dir = up;
break;
case up:
x -= 1;
if (x < 0) stop = true;
else if (ARR[x][y - 1] == 0) dir = left;
}
if (stop) break;
}
}
Answer the question
In order to leave comments, you need to log in
It should be like this
int direct(const int rows, const int cols, int** ARR);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question