Article View: csu.cs
Article #65I hate c
From: Adam Carheden
Date: Sat, 22 Apr 2000 00:00
Date: Sat, 22 Apr 2000 00:00
32 lines
1377 bytes
1377 bytes
I have a c question, which, like most c questions, probably lies in the
misunderstanding of pointers:
I declare the following:
struct servent *udp_service;
struct servent *tcp_service;
Later, I call getservicebyname to fill them:
udp_service = getservbyname("cs457", "udp");
tcp_service = getservbyname("cs457", "tcp");
Next, I print the results:
printf("UDP Protocol = %s\nTCP Protocol = %s\n", udp_service->s_proto,
tcp_service->s_proto);
This produces the following output:
UDP Protocol = tcp
TCP Protocol = tcp
If I reverse the order of the getservbyname lines, I get the opposite:
UDP Protocol = udp
TCP Protocol = udp
Both structures always point to the same thing. Why?
--
Adam Carheden
carheden@holly.ColoState.EDU
Technical Details
Message-ID:
<39024CF4.C4286D1D@holly.ColoState.EDU>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 148df6,cb61e576f2f3a144,start X-Google-Attributes: gid148df6,public X-Google-Thread: 11c4c0,cb61e576f2f3a144,start X-Google-Attributes: gid11c4c0,public From: Adam Carheden <carheden@holly.ColoState.EDU> Subject: I hate c Date: 2000/04/22 Message-ID: <39024CF4.C4286D1D@holly.ColoState.EDU> X-Deja-AN: 614484323 Content-Transfer-Encoding: 7bit X-Accept-Language: en-US, en Content-Type: text/plain; charset=us-ascii X-Trace: 22 Apr 2000 19:08:34 -0700, dialup0441.ppp.colostate.edu MIME-Version: 1.0 Newsgroups: csu.cs,csu.cs.c++