passing a value of a variable from one function to another

  • Follow


hi guys,

Supposidly i have a function

code:--------------------------------------------------------------------------------
decode_ip(u_char *packet, u_char flags)
--------------------------------------------------------------------------------


that has a variable which is 


code:--------------------------------------------------------------------------------
char destination_ip[40]; //Here we save destination IP
--------------------------------------------------------------------------------


where we save a specific value

code:--------------------------------------------------------------------------------

/*Kifah this part is for saving destination IP somewhere*/
			sprintf(destination_ip,"%d.%d.%d.%d",
			(packet[16] & 0xff),
			(packet[17] & 0xff),
			(packet[18] & 0xff),
			(packet[19] & 0xff));
--------------------------------------------------------------------------------



Now i wanna "pass" the value saved in it, to another function:


code:--------------------------------------------------------------------------------

void socket_connect(struct scoop_pack *vp)
{
..
..
..
//something maybe like?
their_addr.sin_addr.s_addr  = inet_addr(destination_ip);
--------------------------------------------------------------------------------



Is that possible? how would be able to pass it then?

Thanks in advance
0
Reply kifah (10) 1/29/2004 8:03:08 PM

Kifah Abbad wrote:

> hi guys,
> 
> Supposidly i have a function
> that has a variable which is
> char destination_ip[40]; //Here we save destination IP
> 
> Now i wanna "pass" the value saved in it, to another function:
> 
> their_addr.sin_addr.s_addr  = inet_addr(destination_ip);
> Is that possible? how would be able to pass it then?

You pass destination_ip (which decays to a pointer to char, which
is compatible with a pointer to a const qualified char in case
your inet_addr() happens to expect a pointer to a const qualified
char) to inet_addr().

You cannot pass an array to a function, but in most cases, your's
included, you don't want to. You cannot pass "variables" to functions
in C, but you can pass values of expressions. 

The parameters are local variables of your function that are initialized
with the values that you pass to the function. The value of the expression

   destination_ip

is a pointer to the first element of destination_ip. If inet_addr() happens
to be defined as

   funny_type inet_addr(char const *verbose_address)
   {
   }

then verbose_address inside inet_addr() starts its life initialized with 
the value of the expression you passed to inet_addr(), i.e. a pointer to
the first element if destination_ip.

Kurt

0
Reply watzka (20) 1/29/2004 8:39:50 PM


1 Replies
44 Views

(page loaded in 0.169 seconds)

Similiar Articles:













7/9/2012 11:27:54 AM


Reply: