Hello,
I have one problem, and can think of two possible solutions but I
can't manage to make them work. I'm open to other suggestions if you
thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know
how to tell it where to send the socket. ( I think I'm messing it up
with pointers)
struct hostent *hp;
sendSocket(){
hp= gethostbyname(PROBLEM HERE);
}
main(){
sendSocket();
}
[Possible First Solution]
This would be probably the best approach to what I need. Ask the user
for the hostname
sendSocket(){
char hostname[256];
printf("Enter hostname: ");
fgets ( hostname, 256, stdin );
hp= gethostbyname(¿WHAT SHOULD I PUT HERE?);
}
[Possible Second Solution]
A way to make argc and argv available outside the main function.
struct hostent *hp;
sendSocket(){
hp = gethostbyname(argv[1]);
}
main(int argc; char *argv[]){
sendSocket();
}
Any suggestion? Thanks 5 2711 ru****@gmail.com wrote: Hello,
I have one problem, and can think of two possible solutions but I can't manage to make them work. I'm open to other suggestions if you thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know how to tell it where to send the socket. ( I think I'm messing it up with pointers)
struct hostent *hp;
sendSocket(){ hp= gethostbyname(PROBLEM HERE); }
main(){
int main(void) { sendSocket(); }
As such things are handled in a platform specific way (they are not part
of standard C) please ask in a forum specific to your platform.
[And, of course, you *should* have read the FAQ before posting.]
HTH,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Hi,
Sorry. I found that the cause why the first solution didn't work was
the '\n' being introduced in the last position before '\0'.
Thank you Artie. I read the FAQ but didn't find anything about this,
sorry if this wasn't the appropriate group.
Bye
Artie Gold wrote: ru****@gmail.com wrote: Hello,
I have one problem, and can think of two possible solutions but I can't manage to make them work. I'm open to other suggestions if you thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know how to tell it where to send the socket. ( I think I'm messing it up with pointers)
[...] As such things are handled in a platform specific way (they are not part of standard C) please ask in a forum specific to your platform.
[And, of course, you *should* have read the FAQ before posting.]
While the example is using gethostbyname(), the real question being
asked is "how can I get a string from the user, and pass it to a
function", which would certainly not be off-topic. The fact that
the function is gethostbyname() and not print_foo(), is irrelevant
in this instance.
His followup post showed he found the correct answer -- that fgets()
leaves the newline intact, and he had to remove it before passing the
string to the function.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Kenneth Brody wrote: Artie Gold wrote:
ru****@gmail.com wrote:
Hello,
I have one problem, and can think of two possible solutions but I can't manage to make them work. I'm open to other suggestions if you thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know how to tell it where to send the socket. ( I think I'm messing it up with pointers)
[...]
As such things are handled in a platform specific way (they are not part of standard C) please ask in a forum specific to your platform.
[And, of course, you *should* have read the FAQ before posting.]
While the example is using gethostbyname(), the real question being asked is "how can I get a string from the user, and pass it to a function", which would certainly not be off-topic. The fact that the function is gethostbyname() and not print_foo(), is irrelevant in this instance.
His followup post showed he found the correct answer -- that fgets() leaves the newline intact, and he had to remove it before passing the string to the function.
Point taken.
However, even in a case like that, it behooves the OP to provide a
visible prototype for any non-standard function (yes I know what
gethostbyname() does -- but not when I'm wearing this hat ;-)).
Cheers,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Artie Gold <ar*******@austin.rr.com> wrote:
# However, even in a case like that, it behooves the OP to provide a
# visible prototype for any non-standard function (yes I know what
# gethostbyname() does -- but not when I'm wearing this hat ;-)).
When you find yourself in a hole, stop digging.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
What kind of convenience store do you run here? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: yawnmoth |
last post by:
using the gethostbyname function seems to noticeably slow down pages.
some of the comments in php.net's gethostbyname entry suggest using a
version that caches the result, but those versions also...
|
by: Fortepianissimo |
last post by:
I've tried using
socket.setdefaulttimeout(timeout)
to set the default timeout to 'timeout' for all sockets. The part
that's not clear to me, is that if this will affect...
|
by: Glen Conway |
last post by:
Hi,
I'm trying to use the gethostbyname function from wsock32.dll and failing dismally Has anyone got a successful implementation of this in VB.NET? My ulitimate goal is to resolve NetBIOS names...
|
by: Quentin Carbonneaux |
last post by:
Hello,
I'm writing a little program which has to get a FQDN on his stdin and
return the IP on stdout, we can do it easily with gethostbyname call
but I would like to set up a timeout to this...
|
by: KL |
last post by:
I have a problem trying to write to a binary file that I want to name
after a particular name from a set. My code for the function follows,
please excuse the horrible mistakes you may see, I am a...
|
by: Ryan Liu |
last post by:
Hi,
I have problem to connect to database server from a windows 98 machine.
I look at exception trace log, the problem seems not because of database
driver itself.
Seems the problem is...
|
by: yawnmoth |
last post by:
I seem to be getting conflicting gethostbyname behavior on different
servers. Before going into detail, here's the script I'm using:
<?
$address = $HTTP_SERVER_VARS;
$rev =...
|
by: Andrew DeFaria |
last post by:
I've been having problems with my ISP. One way it seems to manifest
itself is that I can not reach or contact my ISP's DNS servers. IOW a
simply nslookup google.com will fail.
So I tried writing...
|
by: aj |
last post by:
I have the following snippet of code. On some platforms, the delete
calls works, on Linux, it core dumps (memory dump) at the delete
call. Am I responsible for deleting the memory that...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
| |