a special type of function

S

Sheldon

Hi,

I want to write function that is of type: void Funt(long az, double
bt, long *ar1, double *ar2)
I got the function to work for the arrays: ar1 and ar2 but I don't
know how to get it to work for variables: az and bt.

Can anyone show me if and how this is possible.

Thanks,
/Sheldon
 
U

user923005

Hi,

I want to write function that is of type: void Funt(long az, double
bt, long *ar1, double *ar2)
I got the function to work for the arrays: ar1 and ar2 but I don't
know how to get it to work for variables: az and bt.

If you want to modify the contents of the variables az and bt, you
have to pass their addresses.
In C, all objects passed into functions are copies of the original.
So if you want to change the original object, just pass in the address
of the object and manipulate it that way.

This is just my guess, and my Karnak hat has gone missing so if you
really want to know about something else, you might spell out exactly
what you have tried and exactly what is going wrong, along with a copy/
paste of the actual code you are using.
 
J

James Kuyper

Sheldon said:
Hi,

I want to write function that is of type: void Funt(long az, double
bt, long *ar1, double *ar2)
I got the function to work for the arrays: ar1 and ar2 but I don't
know how to get it to work for variables: az and bt.

Can anyone show me if and how this is possible.

Absolutely the simplest way to do this is to write:

void Funt(long az, double bt, long *ar1, double *ar2) {}

If that doesn't meet your needs (I certainly don't expect it to), then
you're going to have to tell us what you're actually having problems
with. What have you tried to do, and how has it failed?

I can tell you this - there's nothing about your function type that is a
problem. It might not be appropriate for the purpose for which you
intend to use that function, but in order to address that issue we have
to know what the intended use is.
 
S

Sheldon

If you want to modify the contents of the variables az and bt, you
have to pass their addresses.
In C, all objects passed into functions are copies of the original.
So if you want to change the original object, just pass in the address
of the object and manipulate it that way.

This is just my guess, and my Karnak hat has gone missing so if you
really want to know about something else, you might spell out exactly
what you have tried and exactly what is going wrong, along with a copy/
paste of the actual code you are using.

Thanks! It works!

/M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top