sub proceedure/function Qs

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

Join Date: Mar 2008
Posts: 63
Reputation: 666kennedy is an unknown quantity at this point 
Solved Threads: 0
666kennedy 666kennedy is offline Offline
Junior Poster in Training

sub proceedure/function Qs

 
0
  #1
Nov 19th, 2008
this is my sub proceedure

  1. /******************************************************************************
  2.  *
  3.  * Name: patpixselect
  4.  * Parameters: none
  5.  * Returns: patpix[]
  6.  * Globals: none
  7.  * Description: database for which pixels for which pattern
  8.  *****************************************************************************/
  9.  
  10. int patpixselect (int pat);
  11. {
  12. float patpix[9] ; // array for pixels in patterns
  13.  
  14.  
  15.  
  16. if (pat == 1)
  17. {
  18. patpix[0] = 1;
  19. patpix[1] = 1;
  20. patpix[2] = 1;
  21. patpix[3] = 1;
  22. patpix[4] = 1;
  23. patpix[5] = 1;
  24. patpix[6] = 1;
  25. patpix[7] = 1;
  26. patpix[8] = 1;
  27. ++pat;
  28. return (patpix[9], pat)
  29. }
  30. if (pat == 2)
  31. {
  32. patpix[0] = 2;
  33. patpix[1] = 2;
  34. patpix[2] = 2;
  35. patpix[3] = 2;
  36. patpix[4] = 2;
  37. patpix[5] = 2;
  38. patpix[6] = 2;
  39. patpix[7] = 2;
  40. patpix[8] = 2;
  41. ++pat;
  42. return (patpix[9], pat)
  43. }
  44. if (pat == 3)
  45. {
  46. patpix[0] = 3;
  47. patpix[1] = 3;
  48. patpix[2] = 3;
  49. patpix[3] = 3;
  50. patpix[4] = 3;
  51. patpix[5] = 3;
  52. patpix[6] = 3;
  53. patpix[7] = 3;
  54. patpix[8] = 3;
  55. pat = 1;
  56. return (patpix[9], pat)
  57. }
  58.  
  59. }

will this work? will i need to declare the array before i call the sub proceedure and can i return both those pieces of info?

the array needs to be a float because the numbers wont be integers when i go to run the program properly.
"pat" is declared before it enters the function, and its number dictates which array values are used in the main program. not sure whether it is needed to be returned unless pat being incrimented isnt recognised in main program, also pretty sure now that pat shouldnt be in that return bracket

im not sure if this is correct
the values of the array is the important thing
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,818
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: sub proceedure/function Qs

 
0
  #2
Nov 19th, 2008
Originally Posted by 666kennedy View Post
this is my sub proceedure

  1. /******************************************************************************
  2.  *
  3.  * Name: patpixselect
  4.  * Parameters: none
  5.  * Returns: patpix[]
  6.  * Globals: none
  7.  * Description: database for which pixels for which pattern
  8.  *****************************************************************************/
  9.  
  10. int patpixselect (int pat);
  11. {
  12. float patpix[9] ; // array for pixels in patterns
  13.  
  14.  
  15.  
  16. if (pat == 1)
  17. {
  18. patpix[0] = 1;
  19. patpix[1] = 1;
  20. patpix[2] = 1;
  21. patpix[3] = 1;
  22. patpix[4] = 1;
  23. patpix[5] = 1;
  24. patpix[6] = 1;
  25. patpix[7] = 1;
  26. patpix[8] = 1;
  27. ++pat;
  28. return (patpix[9], pat)
  29. }
  30. if (pat == 2)
  31. {
  32. patpix[0] = 2;
  33. patpix[1] = 2;
  34. patpix[2] = 2;
  35. patpix[3] = 2;
  36. patpix[4] = 2;
  37. patpix[5] = 2;
  38. patpix[6] = 2;
  39. patpix[7] = 2;
  40. patpix[8] = 2;
  41. ++pat;
  42. return (patpix[9], pat)
  43. }
  44. if (pat == 3)
  45. {
  46. patpix[0] = 3;
  47. patpix[1] = 3;
  48. patpix[2] = 3;
  49. patpix[3] = 3;
  50. patpix[4] = 3;
  51. patpix[5] = 3;
  52. patpix[6] = 3;
  53. patpix[7] = 3;
  54. patpix[8] = 3;
  55. pat = 1;
  56. return (patpix[9], pat)
  57. }
  58.  
  59. }

will this work? will i need to declare the array before i call the sub proceedure and can i return both those pieces of info?

the array needs to be a float because the numbers wont be integers when i go to run the program properly.
"pat" is declared before it enters the function, and its number dictates which array values are used in the main program. not sure whether it is needed to be returned unless pat being incrimented isnt recognised in main program, also pretty sure now that pat shouldnt be in that return bracket

im not sure if this is correct
the values of the array is the important thing

You have some semicolon problems and you have a potential segmentation fault. Why are you using the comma operator? If you are trying to return an array:

* Returns: patpix[]
then change the function so it returns a pointer to an array instead of an integer:

int* patpixselect (int pat);

See this thread:
http://www.daniweb.com/forums/thread5939.html
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC