Error C2100: Illegal Indirection

After a lot of research I found out some things that I would like to verify and use in my homework. When passing a 2D array to a function as pointer, it is treated as a 1D, so hypothetically on the same line, is that right to say?
So if I want to find the address of a cell (int) I just add +4n?
And now for my homework:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <time.h>
#include<iomanip>
#include<array>
#include <algorithm>

using namespace std;
const int AS = 6;
void FillingRandomly(int (*)[AS]);
void printing(int (*)[AS]);


int c;

int main()

{
	int funny = 0;
	int timpa = 0;
	int counter = 0;
	int Array[AS][AS];
	srand(time(0));


	FillingRandomly(Array);	
	

	cout << "The unsorted array is" << endl << endl;

	printing(Array);

	cout << "The sorted array is" << endl << endl;

	printing(Array);

	

		

	
	
	system("PAUSE");


	return 0;

}

void FillingRandomly(int *ArrayPtr)
{for(int i=0;i<AS;i++)
{for (int j=0;j<AS;j++)
{
*(*(ArrayPtr +i)+j)=rand()%56+2;
}
		}
}

void printing(int *Array)
{
	for(int i=0;i<AS;i++)
	{for (int j=0;j<AS*AS;j++)
	{int counter = 0;

	cout<<((Array[i] +j))<<setw(5);

			if ((Array[i] +j)%AS == 0)
				cout << endl << endl;
	}	
}
}

void forsorting(int *Brray, int funny)
{
	int dice = 0;
	int super = 0;
	int space=0;
	

	//Sorting Array[][] which is treated like Array[]

{

 for (int pass = 0; pass < AS - 1; pass++) {
        
         for (int k = 0; k < AS - 1; k++) {
            int temp;
            
                if(*(Brray+k)==*(Brray+k+1))
{
    temp=*(Brray+k);
    *(Brray+k)=*(Brray+k+1);
    *(Brray+k+1)=temp;
}
    } 

 }
}
}


I have to create a program which has 3 functions, one to create and fill an array at random, one to print it on the screen, and one to sort it. Im only having about 2 errors that I cant seem to know how to fix Error 2 error C2100: illegal indirection c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\finalll\finalll\finalll.cpp 55
and related to it Error 3 error C2106: '=' : left operand must be l-value c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\finalll\finalll\finalll.cpp 55
and 4 IntelliSense: operand of '*' must be a pointer c:\Users\pc\Desktop\USB\Anthony\Documents\Visual Studio 2012\Projects\Finalll\Finalll\Finalll.cpp 55
.

Im pretty sure that the sorting technique is correct as its the same as the one in my course, but Im not too sure about the usage of the pointers.

Sorry if my english is not too good, it's not my main language
Thank you
Your prototypes don't match your definitions:

1
2
3
4
5
6
7
void FillingRandomly(int (*)[AS]);   // lines 11-12... these are correct
void printing(int (*)[AS]);


void FillingRandomly(int *ArrayPtr)  // line 51 .. this doesn't match -- it's wrong

void printing(int *Array) // line 60 .. also doesn't match 

1
2
void FillingRandomly(int (*)[AS]); //declaration line 11
void FillingRandomly(int *ArrayPtr) //definition line 51 
they do not refer to the same function.


About the error
*(*(ArrayPtr +i)+j)=rand()%56+2;
`ArrayPtr' is a pointer to an int, so `ArrayPtr[i]' is an int
It does not make sense to say `42[13]'
Any idea how to fix this?
Have your definitions match your prototype:

1
2
3
4
5
6
7
8
9
10
11
12
13
// These are your prototypes.  They are correct
void FillingRandomly(int (*)[AS]);
void printing(int (*)[AS]);


// These are your definitions, they are wrong
void FillingRandomly(int *ArrayPtr)
void printing(int *Array)


// change them to match your prototypes:
void FillingRandomly( int (*ArrayPtr)[AS] )
void printing( int (*Array)[AS] )
Topic archived. No new replies allowed.