C “有关”的编译错误;“前应为说明符限定符列表”;

C “有关”的编译错误;“前应为说明符限定符列表”;,c,gcc,compiler-errors,C,Gcc,Compiler Errors,我刚开始我的网络作业关于网络,但立即有一个恼人的错误 #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <stdlib.h> #include <pthre

我刚开始我的网络作业关于网络,但立即有一个恼人的错误

#include <stdio.h>  
#include <sys/types.h>  
#include <sys/socket.h>  
#include <netinet/in.h>  
#include <arpa/inet.h>  
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>

typedef struct client_table{
    struct sockaddr_in server_addr;
    server_addr.sin_family=AF_INET;
    memset(&server_addr,0,sizeof(server_addr));
    struct client_table *next;
    int client_no;
} client_table;

我在谷歌上搜索过,但没有任何帮助。请帮我解决它。提前感谢。

要进一步详细说明Marion的评论

“struct”是一个变量声明(类似于“int i;”),不能包含代码,例如server_add.sin_系列的AF_INET赋值和memset调用。这些操作必须在其他地方执行,可能是在main()中?虽然可以预初始化结构,但必须以类似于初始化任何其他变量(即“int i=0;”)的方式进行,但必须为所有结构字段指定值,用逗号分隔,并用大括号括起来。如果您有嵌套结构(如server_addr),则该元素的初始化数据必须是另一个结构初始值设定项,并指定所有字段,然后再次用大括号括起来。就我个人而言,我只是将这两行可执行代码移到main()并完成它

下面是嵌套结构初始化的一个更简化的示例:

struct coord {
    int x, y;
};
struct box {
    struct coord  upperleft;
    struct coord  lowerright;
} big_box = { { 10, 10 }, { 0, 0 } };

不能将代码放入类型/结构定义中。这两条线应该定义什么<代码>服务器地址sin\u family=AF\u INET;memset(&server_addr,0,sizeof(server_addr))
struct coord {
    int x, y;
};
struct box {
    struct coord  upperleft;
    struct coord  lowerright;
} big_box = { { 10, 10 }, { 0, 0 } };