943,972 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 16307
  • C++ RSS
Mar 14th, 2005
0

Passing Arrays to function in Visual C++

Expand Post »
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"

C++ Syntax (Toggle Plain Text)
  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 >>
Similar Threads
F50
Reputation Points: 10
Solved Threads: 0
Newbie Poster
F50 is offline Offline
6 posts
since Feb 2005
Mar 14th, 2005
0

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..
F50
Reputation Points: 10
Solved Threads: 0
Newbie Poster
F50 is offline Offline
6 posts
since Feb 2005
Mar 14th, 2005
0

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.
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: make directory
Next Thread in C++ Forum Timeline: Sorting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC