473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

passing a value of a variable from one function to another

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
Nov 14 '05 #1
1 4315
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

Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
1
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
9
by: zholthran | last post by:
Hi folks, after reading several threads on this issue (-> subject) I fear that I got a problem that cannot easily be solved by the offered workarounds in an acceptable way, at least not with my...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
2
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would...
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.