DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Passing Arrays to function in Visual C++ (http://www.daniweb.com/forums/thread20180.html)

F50 Mar 14th, 2005 3:14 pm
Passing Arrays to function in Visual C++
 
This seems like a simple task but the microsoft visual c++ 6.0 compiler is giving me a problem with this. Its complaining about the lines where i try to use a passed array such as "fin[i]=0".

Its giving this error for the following code.

"error C2109: subscript requires array or pointer type"

void main()
{


///// data structures for banker's //////////////////

//avaliable resources, actually only one, which is bank's Money.
int r_avaliable;               
int curr_allocation[NUM_PROCESSES];        //current allocation of resources (money) to each Process (Client)
int max[NUM_PROCESSES];                                //max demand of each process
int need[NUM_PROCESSES];                                //remaining resource need of each process

int request[NUM_PROCESSES];        //requests of clients for money.

//used for safety algorithm
int finish[NUM_PROCESSES];

int ret;
ret = safety(r_avaliable, need, finish);

} //end Main ()





int safety (int ava, int nd[], int fin[])
{

        //initialize work to avaliable, using ava so, OK.
        //initialize finish[i]= false for all i =1,2,3,etc..
        for (int i=0; i<=NUM_PROCESSES; i++)
        {
        fin[i]=0;
        }

        //find i such that both,
        //finish[i]= false and
        //Needi <= Work (avaliable)

        for (int j=0; j <=NUM_PROCESSES; j++)
        {
                //look for an unmarked process
                if ((fin[j]==false) &&  (nd[j] < ava[1]))
                {
                        //if found
                        //A = A+Ci
                        //Ci = 0;
                }

                //else
                else
                {
                        //loop = false
                }

        } //end for

return 1;
} //end safety

//function prototypes
bool safety(int , int [NUM_PROCESSES] , int [NUM_PROCESSES]);


<< moderator edit: added [code][/code] tags >>

F50 Mar 14th, 2005 3:22 pm
Re: Passing Arrays to function in Visual C++
 
nevermind i figured out the problem.

if ((fin[j]==false) && (nd[j] < ava[1]))

I changed ava to an int instead of an array of ints. So it should look like this:

if ((fin[j]==false) && (nd[j] < ava))


thanks anyways..

Tight_Coder_Ex Mar 14th, 2005 6:15 pm
Re: Passing Arrays to function in Visual C++
 
Quote:

Originally Posted by F50
if ((fin[j]==false) && (nd[j] < ava[1]))

Your function definition declares "ava" as an it, but your trying to use as if it was an array. This wasn't too hard to spot, but in the furture please include everything so it can be pasted into compiler without modification.


All times are GMT -4. The time now is 5:20 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC