[code="java"] #include
#include
#include
#include
#include
#include
#include
#include
#define SERVPORT 3333
#define BACKLOG 10
main(){
int sockfd,client_fd;
struct sockaddr_in my_addr;
struct sockaddr_in remote_addr;
if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1){
perror("socket create erro");
exit(1);
}
my_addr.sin_port=htons(SERVPORT);
my_addr.sin_family=AF_INET;
my_addr.sin_addr.s_addr=INADDR_ANY;
bzero(&(my_addr.sin_zero),8);
if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))==-1){
perror("bind error");
exit(1);
}
if(listen(sockfd,BACKLOG)==-1){
perror("lister error");
exit(1);
}
}
while(1) {//在这里报错service.c:39
int sin_size=sizeof(struct sockaddr_in);
if((client_fd=accrpt(sockfd,(struct sockaddr *)$remote_addr,$sin_addr))==-1){
perror("accept error");
continue;
}
printf("received a connection from %s\n",inet_ntoa(remote_addr.sin_addr));
if(!fork()){
if(send(clint_fd,"hello qiao ",11,0)==-1){
perror("send error");
close(client_fd);
exit(0);
}
close(client_fd);
}
}[/code]
service.c:39: 错误:expected identifier or ‘(’ before ‘while’
[b]问题补充:[/b]
上面的代码是用vi写的,能推荐一个linux下编写c的工具吗????
[b]问题补充:[/b]
我已经2年没有搞c了,毕业了直接搞java开发,现在公司要我搞linux c开发,有点不习惯,看不惯c的结构.我比较喜欢java和动态语言的,