Passing Arrays to function in Visual C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 6
Reputation: F50 is an unknown quantity at this point 
Solved Threads: 0
F50 F50 is offline Offline
Newbie Poster

Passing Arrays to function in Visual C++

 
0
  #1
Mar 14th, 2005
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"

  1. void main()
  2. {
  3.  
  4.  
  5. ///// data structures for banker's //////////////////
  6.  
  7. //avaliable resources, actually only one, which is bank's Money.
  8. int r_avaliable;
  9. int curr_allocation[NUM_PROCESSES]; //current allocation of resources (money) to each Process (Client)
  10. int max[NUM_PROCESSES]; //max demand of each process
  11. int need[NUM_PROCESSES]; //remaining resource need of each process
  12.  
  13. int request[NUM_PROCESSES]; //requests of clients for money.
  14.  
  15. //used for safety algorithm
  16. int finish[NUM_PROCESSES];
  17.  
  18. int ret;
  19. ret = safety(r_avaliable, need, finish);
  20.  
  21. } //end Main ()
  22.  
  23.  
  24.  
  25.  
  26.  
  27. int safety (int ava, int nd[], int fin[])
  28. {
  29.  
  30. //initialize work to avaliable, using ava so, OK.
  31. //initialize finish[i]= false for all i =1,2,3,etc..
  32. for (int i=0; i<=NUM_PROCESSES; i++)
  33. {
  34. fin[i]=0;
  35. }
  36.  
  37. //find i such that both,
  38. //finish[i]= false and
  39. //Needi <= Work (avaliable)
  40.  
  41. for (int j=0; j <=NUM_PROCESSES; j++)
  42. {
  43. //look for an unmarked process
  44. if ((fin[j]==false) && (nd[j] < ava[1]))
  45. {
  46. //if found
  47. //A = A+Ci
  48. //Ci = 0;
  49. }
  50.  
  51. //else
  52. else
  53. {
  54. //loop = false
  55. }
  56.  
  57. } //end for
  58.  
  59. return 1;
  60. } //end safety
  61.  
  62. //function prototypes
  63. bool safety(int , int [NUM_PROCESSES] , int [NUM_PROCESSES]);


<< moderator edit: added [code][/code] tags >>
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 6
Reputation: F50 is an unknown quantity at this point 
Solved Threads: 0
F50 F50 is offline Offline
Newbie Poster

Re: Passing Arrays to function in Visual C++

 
0
  #2
Mar 14th, 2005
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..
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: Passing Arrays to function in Visual C++

 
0
  #3
Mar 14th, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC