When I initialize variables, I do bellow.
int i = 0;
char *myText = NULL;
Then, haw can I initialize struct sockaddr_in type variables?
struct sockaddr_in addr = ?;
If you want to set all fields to zero in a declaration, no matter the structure, then do e.g.
struct some_struct var = { 0 };
you can use memset
Lets say you want to initialize the entire addr structure variable to 0, you can do it as follows.
memset(&addr, 0, sizeof(struct sockaddr_in));
If you want to initialize it using different values you can refer to the example here
http://www.thegeekstuff.com/2011/12/c-socket-programming/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With