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:
and then I am trying to do something like this:
char ip[IP]; /*12 digits, 3 '.' and a null character, is the max length of an IP*/
struct sockaddr_in client;
typedef struct clients Clients;
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.
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;
(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)
2) I have an array of these structures, and when I try to book off each element of the array, ie something like:
I get "error: conversion to non-scalar type requested".
clientTable[clientCount -1] = (Clients)malloc(sizeof(Clients));
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!