Pointer to a struct within an array Help Please 
Author Message
 Pointer to a struct within an array Help Please

I am not sure if this is the correct group but here goes.

Thanks in advance for any help.

I have the following struct:

struct PlayerData {
                struct sockaddr_in addr;
                int fd;
                }Player[5];

I need to pass a pointer to accept();  to Player[variable].addr

i.e.   ....        accept(sockfd, (struct
sockaddr_in *)Player[variable].addr, &addr_length);

variable is already set as type int and  addr_length = sizeof(struct
sockaddr_in)

I am getting the following errors using gcc on Linux 2.0.30

.cannot convert pointer to type
.warning: passing arg 2 of 'accept' from incompatible pointer type

I admitedly am very new to pointers and still have problems, any help
would be greatly appreciated.

Thanks,
James A Culp III
aka illitrit



Mon, 15 Jan 2001 03:00:00 GMT  
 Pointer to a struct within an array Help Please
On Thu, 30 Jul 1998 15:44:35 +0000, James A Culp III

Quote:

>struct PlayerData {
>                struct sockaddr_in addr;
>                int fd;
>                }Player[5];
>I need to pass a pointer to accept();  to Player[variable].addr

A pointer is generated with the "&" operator.  Just like you did with
addr_length.

Quote:
>accept(sockfd, (struct sockaddr_in *)Player[variable].addr, &addr_length);

accept(sockfd, &Player[variable].addr, &addr_length);

--

http://www.cs.wustl.edu/~jxh/        Washington University in Saint Louis

Quote:
>>>>>>>>>>>>> I use *SpamBeGone* <URL:http://www.internz.com/SpamBeGone/>



Mon, 15 Jan 2001 03:00:00 GMT  
 Pointer to a struct within an array Help Please

Quote:

> I am not sure if this is the correct group but here goes.

> Thanks in advance for any help.

> I have the following struct:

> struct PlayerData {
>                 struct sockaddr_in addr;
>                 int fd;
>                 }Player[5];

> I need to pass a pointer to accept();  to Player[variable].addr

> i.e.   ....        accept(sockfd, (struct
> sockaddr_in *)Player[variable].addr, &addr_length);

> variable is already set as type int and  addr_length = sizeof(struct
> sockaddr_in)

> I am getting the following errors using gcc on Linux 2.0.30

> .cannot convert pointer to type
> .warning: passing arg 2 of 'accept' from incompatible pointer type

Try this:

accept(sockfd, &(Player[variable].addr), &addr_length);

Regards,
--
Wei



Tue, 23 Jan 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. help: accessing a pointer to a list within an array of structures

2. struct.array works - struct->pointer not

3. Pointer to struct function NEWBIE PLEASE HELP

4. Please help me with Pointers and Structs

5. Please help <pointer to the struct>

6. Please help me with passing struct Returning from function - pointer to

7. Help: Pointer to 2-D array of structs.

8. Help wanted with array of pointers to structs

9. Help: Pointer to 2-D array of structs.

10. array of pointers to array of structs

11. qsorting & managing struct arrays, pointer arrays

12. Please help~~Array and Pointer

 

 
Powered by phpBB® Forum Software