2 Errors in passing values/references to function

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
#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 *Array)
{for(int i=0;i<AS;i++)
{for (int j=0;j<AS;j++)

*Array[i][j]=rand()%87 +12;

		}
}

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

	cout<<*Array[i][j];

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


Basically I have to create an array, fill it, and then print it on screen. The tricky thing is that need to use pointers to fill it and print and later on sort it. My problem is that with this code is that i get Error 2 error C2109: subscript requires array or pointer type c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\essaie\essaie\essaie.cpp 55
and 5 IntelliSense: expression must have pointer-to-object type c:\Users\pc\Desktop\USB\Anthony\Documents\Visual Studio 2012\Projects\Essaie\Essaie\Essaie.cpp 55
whenever I try to run it.

Any ideas how to solve this?
Last edited on
http://ideone.com/v7Ea0G

What is your line 101 and 102 supposed to be doing? I don't even know what you expect that to do.

EDIT: For some reason you decided to replace your old code with different code. Here is the new ideone link:
http://ideone.com/t4Wulq
Last edited on
Given int *Array[AS][AS], what is the type of &Array[k]?

Your swap expects int * const. That type is not even close.
Standard library has template for std::swap. It cannot accept your type.


Edit: Aha! You did edit out your original question and replace it with something else. Not nice.

The code that I see now leads to counter-question(s):

You do *foo[a][b] = 7;. It is again quite clear that the type of foo cannot be int *. What would the type have to be in order for the statement to be legal?

Given int * foo, how do you access a memory location somewhere near foo?
Given int foo[Y][X];, foo is not a pointer to integer(s).

How much do you know about passing arrays to functions? Is that a by-value copy operation?
Last edited on
Topic archived. No new replies allowed.