Address of Structure element, and struct malloc
Hi there,
I have 2 questsions:
1) How can I access the address of an element of a structure?
I'm trying to do some basic TCP server things, and I have the following struct defined:
Code:
struct clients
{
char *name;
char ip[IP]; /*12 digits, 3 '.' and a null character, is the max length of an IP*/
int new_sd;
struct sockaddr_in client;
int client_len;
};
typedef struct clients Clients;
and then I am trying to do something like this:
Code:
int clientCount = 0; /*Keep track of the number of clients connected*/
Clients *clientTable; /*Memory will be dynamically allocated here, as clients connect*/
...
clientTable[clientCount -1].&client = &temp_client;
but I get a syntax error before the & token. I have tried various combinations of brackets, including the & at the beginning followed by brackets, etc.., and cannot get this to compile.
(Note: The -1 is because clientCount is the real number of clients connected. So if 1 client is connected, the actual structure that exists is at clientTable[0])
2) I have an array of these structures, and when I try to book off each element of the array, ie something like:
Code:
clientTable[clientCount -1] = (Clients)malloc(sizeof(Clients));
I get "error: conversion to non-scalar type requested".
Do I not have to malloc memory for this structure? Is it considered already malloc'd just by its creation?
Thanks very much for the help!