user235244
user235244

Reputation: 21

How to convert gchar to char?

i am trying to convert gchar to char by this code

const gchar * AddressText ;
char * AddressValue = (char *) AddressText ;
inet_pton(AF_INET,AddressValue, &Addr.sin_addr);

to use it in socket but it seems to not work

Upvotes: 1

Views: 12126

Answers (1)

Mike
Mike

Reputation: 49523

Your question "How to convert gchar to char" has a simple answer, but I don't think it's the question you meant to ask...

gchar, used in gtk, is a glib type just a typedef to a char, so you're done already.

What you're probably trying to ask is "why doesn't my code work", and that requires more code to answer. The inet_pton() function needs the src parameter (your AddressValue) to be populated and since you're passing AF_INET it needs to be populated with an IPv4 address.

The code you're showing passes an uninitialized char pointer to this function... So either that is your problem, or you are not showing your actual code, which means no one can help you.

Note: If you're getting "Connection refused" on 127.0.0.1 there's a good chance your server on your machine isn't running... or (if you wrote it yourself) the problem is with the connection code.

Upvotes: 4

Related Questions