On Saturday, February 21, 1998 2:28 AM, Pure Krome [SMTP:Pure@SPRINT.COM.AU] wrote: > G'day. > This is BOG SIMPLE. How do i return an array from a function in some > file ? > the array was going to hold some valid races .... so i suppose that can > be the connection to circle :) i was doing it with some static int, but > didn't like the messy code i had. Any suggestions please? > > eg. > > funtion foo(..){ > int some_array[SOMENUMBER]; > > ... > do some check on some var .. > insert some numbers in the array .. > > return the array to the function call in another file. > } > > Jussy the blond. Wellll.. returning the entire array isn't really going to happen.. you could do is this (return to a pointer to a dynamically allocated struct that happens to contain an array...) struct some_array { int my_array_of_ints[my_number_of_them]; }; struct some_array *foo() { struct some_array *my_array; CREATE(my_array, struct some_array, 1) if (!my_array) return NULL; /* populate the array here e.g. my_array->my_array_of_ints[x]=y; */ return my_array; } void main() { struct some_array *da_array; da_array = foo(); if (!da_array) { /* insert complaint code here */ } } I think that'd work.. though I just cooked it up and didn't test it. You can be sure there'll be one compiler errror.. there always seems to be with mailer code ;-) You could also get a hold of a copy of the C usenet FAQ.. good reading for stuff like this.. and searchable.. faster than posting on the list. There are also a lot of resources on the web that can help.. just construct a good search key for your favorite search engine.. And best of all, it wouldn't be mailer code *grin* --Mallory +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST