Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,058 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,556 people online right now. Registration is fast and FREE... Join Now!




LValue ?

 
Reply to this topicStart new topic

LValue ?, I keep getting this error

UG Cyber
4 Aug, 2008 - 08:49 PM
Post #1

D.I.C Head
**

Joined: 24 Jul, 2008
Posts: 185



Thanked: 3 times
My Contributions
Well i am trying to make the same Chat program user friendly for one of my buddys (this sucks, I'm not even getting paid for all of this trouble mad.gif ) However i think it would be in my best interest to find out what 'LValue' is.... Here is the lines that its having problems with
CODE

char IP[30];
IP = gethostbyname(Host);
error=WSAStartup(0x0202, &wsadata);


It brings me just after the '=' when i try to get host by its name and says

[C++ Error] Unit1.cpp(26): E2277 Lvalue required

I'm using Borland Builder 6
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: LValue ?
4 Aug, 2008 - 09:25 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
I believe gethostbyname actually returns a pointer to a hostent structure. Not a char array. Check out the function again and change it accordingly.LValue is the value on the left hand side of the equals sign.

smile.gif
User is online!Profile CardPM
+Quote Post

UG Cyber
RE: LValue ?
5 Aug, 2008 - 07:58 AM
Post #3

D.I.C Head
**

Joined: 24 Jul, 2008
Posts: 185



Thanked: 3 times
My Contributions
QUOTE(Martyr2 @ 4 Aug, 2008 - 10:25 PM) *

I believe gethostbyname actually returns a pointer to a hostent structure. Not a char array. Check out the function again and change it accordingly.LValue is the value on the left hand side of the equals sign.

smile.gif


Ok that got pass the LValue error but how do i convert that to a char* so i can use the hostent to connect to the client??

User is offlineProfile CardPM
+Quote Post

Hyper_Eye
RE: LValue ?
5 Aug, 2008 - 12:46 PM
Post #4

D.I.C Head
**

Joined: 13 Sep, 2007
Posts: 72



Thanked: 4 times
My Contributions
QUOTE(UG Cyber @ 5 Aug, 2008 - 10:58 AM) *

QUOTE(Martyr2 @ 4 Aug, 2008 - 10:25 PM) *

I believe gethostbyname actually returns a pointer to a hostent structure. Not a char array. Check out the function again and change it accordingly.LValue is the value on the left hand side of the equals sign.

smile.gif


Ok that got pass the LValue error but how do i convert that to a char* so i can use the hostent to connect to the client??


The gethostbyname() man page has the definition of the hostent structure in it. h_addr_list is what your looking for.
User is offlineProfile CardPM
+Quote Post

UG Cyber
RE: LValue ?
5 Aug, 2008 - 01:22 PM
Post #5

D.I.C Head
**

Joined: 24 Jul, 2008
Posts: 185



Thanked: 3 times
My Contributions
Ok so i would have to type this in??
CODE

struct hostent* host;
host = gethostbyname("192.168.0.1");
sock.sin_family = AF_FAMILY;
sock.sin_port = htons(portNo);
sock.sin_addr.s_addr = host(h_addr);


??
User is offlineProfile CardPM
+Quote Post

Hyper_Eye
RE: LValue ?
5 Aug, 2008 - 02:32 PM
Post #6

D.I.C Head
**

Joined: 13 Sep, 2007
Posts: 72



Thanked: 4 times
My Contributions
QUOTE(UG Cyber @ 5 Aug, 2008 - 04:22 PM) *

Ok so i would have to type this in??
CODE

struct hostent* host;
host = gethostbyname("192.168.0.1");
sock.sin_family = AF_FAMILY;
sock.sin_port = htons(portNo);
sock.sin_addr.s_addr = host(h_addr);


??


Try

CODE
sock.sin_addr.s_addr = *((struct in_addr *)host->h_addr);


You may find this site helpful when it comes to socket programming: http://www.beej.us/guide/bgnet/
It is a very popular guide.

This post has been edited by Hyper_Eye: 5 Aug, 2008 - 02:33 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:08PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month