Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing an array as an argument to a func

Status
Not open for further replies.

efittery

Programmer
Joined
Feb 13, 2003
Messages
21
Location
US
The following doesn't work because you can't pass an array name as an argument to a func. Is there a way to accomplish what I am trying by passing a reference to the array I want to search with the "func searchArray"?

Thanks for the help.

proc main

string myArray[10]
integer result

myArray[0] = "hi there"
myArray[1] = "good bye"

result = searchArray( myArray, "good bye" )

termmsg "index for string `"good by`" is: %d", result

endproc

func searchArray : integer

param string searchStr

param string localArray[10]

integer index

for index = 0 upto sizeofarray( localArray )

if ( strcmp( searchStr, localArray[index])
return( index )
endfor

; could not find the search string

return ( -1 )

endfunc
 
My original code was pretty bad. The following is what I am trying to accomplish. I commented out the code that depends on using a "func" and replaced it with straight in line code. The question is how to accomplish the same thing with a "func" and not use inline code.

thanks for the info



proc main

string myArray[10]
integer index
integer result

result = -1

myArray[0] = "hi there"
myArray[1] = "good bye1"
myArray[2] = "good bye2"
myArray[3] = "good bye3"
myArray[4] = "good bye4"
myArray[5] = "good bye5"
myArray[7] = "good bye6"
myArray[6] = "good bye7"

; result = searchArray( "good bye5", myArray )

for index = 0 upto 9

if strcmp "good bye5" myArray[index]
result = index
break
endif

endfor

termmsg "index for string `"good by`" is: %d`n`r", result


endproc

;func searchArray : integer
;
; param string searchStr
;
; param string localArray[10]
;
integer result
; integer index
;
; for index = 0 upto sizeofarray( localArray )
;
; if searchStr localArray[index]
; result = index
break
; endfor
;
; ; could not find the search string
;
; return ( result )
;
;endfunc
 
The only ideas I can come up with is either making your array a global variable, or have the loop in your main procedure, assign yArray to a temporary string variable, and pass that temporary variable to your function.


aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top