Hi,
Quote:
> > My question then, is can a
> > function return more then one data type? For example, say
> > I have a function that is doing my database talk for me and
> > I want it to return a field entry, which is a string, and a
> > value that would be say, just a type int. How can I return
> > those types seperatly from one function without having to
> > regex the hell out of a string, or can I?
Returning a string isn't as easy as it is in Perl. The only thing you can
return is a pointer to a string (or, using Perl-talk again, a reference,
which is not entirely the same). The memory required to store the string
also has to be allocated somewhere in your program (remember to allocate
enough space for the string including the termination 0).
Quote:
> A function can not return more than "one scalar" (using
> Perl-talk), which it really can't do in Perl either BTW. If you
> want to return a structure, define a struct that contains all
> the data that you want to return and then return an object of
> that structure type.
A different solution is to pass storage pointers with the function call,
e.g.:
int myfunc(int in, int* out);
myfunc can store information (in this case of type int) at the location the
out pointer points to. Of course you can pass as many as you want of these
(as long as you prototype your function as such).
A third solution, which noone would recommend I hope, is using global
variables. But pretend you never read that last line.
Good luck with it,
John