当前位置: 技术问答>linux和unix
我写的一个关于线程的程序,为什么编译通不过?
来源: 互联网 发布时间:2016-08-18
本文导语: 源程序: [code=C/C++][/code#include"my_head.h" #define MAXLINE 1024 struct arg//thread arguments { FILE *fp; int sockfd; }; void *read_sock(void *thread_arg); int get_opt(int argc,char **argv); int client_handle(FILE *file,int sock); char port[10];//global v...
源程序:
[code=C/C++][/code#include"my_head.h"
#define MAXLINE 1024
struct arg//thread arguments
{
FILE *fp;
int sockfd;
};
void *read_sock(void *thread_arg);
int get_opt(int argc,char **argv);
int client_handle(FILE *file,int sock);
char port[10];//global variables
char ip_addr[30];
int main(int argc,char **argv)
{
int sock;
struct sockaddr_in server;
int len = sizeof(server);
FILE *file;
file = stdin;
get_opt(argc,argv);
bzero(&server,len);
sock = Socket(AF_INET,SOCK_STREAM,0);
server.sin_family = AF_INET;
server.sin_port = htons(atoi(port));
server.sin_addr.s_addr = inet_addr(ip_addr);
Connect(sock,(struct sockaddr *)&server,len);
client_handle(file,sock);
return(0);
}
int get_opt(int argc,char **argv)//get arguments
{
int opt;
bzero(port,sizeof(port));
bzero(ip_addr,sizeof(ip_addr));
if( argc sockfd,recv_msg,MAXLINE,0) > 0 )
{
fputs(recv_msg,(struct arg *)thread_arg->fp);
bzero(recv_msg,MAXLINE);
}
return(NULL);
}]
错误提示:function ‘read_sock’:
client.c:102: warning: dereferencing ‘void *’ pointer
client.c:102: error: request for member ‘sockfd’ in something not a structure or union
client.c:104: warning: dereferencing ‘void *’ pointer
client.c:104: error: request for member ‘fp’ in something not a structure or union
应该是参数的传递有问题。
[code=C/C++][/code#include"my_head.h"
#define MAXLINE 1024
struct arg//thread arguments
{
FILE *fp;
int sockfd;
};
void *read_sock(void *thread_arg);
int get_opt(int argc,char **argv);
int client_handle(FILE *file,int sock);
char port[10];//global variables
char ip_addr[30];
int main(int argc,char **argv)
{
int sock;
struct sockaddr_in server;
int len = sizeof(server);
FILE *file;
file = stdin;
get_opt(argc,argv);
bzero(&server,len);
sock = Socket(AF_INET,SOCK_STREAM,0);
server.sin_family = AF_INET;
server.sin_port = htons(atoi(port));
server.sin_addr.s_addr = inet_addr(ip_addr);
Connect(sock,(struct sockaddr *)&server,len);
client_handle(file,sock);
return(0);
}
int get_opt(int argc,char **argv)//get arguments
{
int opt;
bzero(port,sizeof(port));
bzero(ip_addr,sizeof(ip_addr));
if( argc sockfd,recv_msg,MAXLINE,0) > 0 )
{
fputs(recv_msg,(struct arg *)thread_arg->fp);
bzero(recv_msg,MAXLINE);
}
return(NULL);
}]
错误提示:function ‘read_sock’:
client.c:102: warning: dereferencing ‘void *’ pointer
client.c:102: error: request for member ‘sockfd’ in something not a structure or union
client.c:104: warning: dereferencing ‘void *’ pointer
client.c:104: error: request for member ‘fp’ in something not a structure or union
应该是参数的传递有问题。
|
(struct arg *)thread_arg 加括号