|
请各位高手帮忙看看程序最后一行到底是什么语法错误(暂不管我程序其他错误)。
程序编译时出现错误以下(54为本程序最后一行):
[root@bing net]# ls
bbs client.c server server.c
[root@bing net]# gcc -o client client.c
client.c: In function `main':
client.c:54: error: syntax error at end of input
[root@bing net]#
程序代码:
[code:1]
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define PORT 1234
#define MAXDATASIZE 100
int main(int argc, char *argv[])
{
int fd, numbytes;
char buf[MAXDATASIZE];
struct hostent *he;
struct sockaddr_in server;
if ( argc!=2)
{
printf( "Useage: %s <IP address >\n", argv[0] );
exit(1);
}
if ((he=gethostbyname (argv[1]))==NULL) {
printf("Gethostbyname error.");
exit(1);
if ((fd=socket(AF_INET, SOCK_STREAM, 0))==-1) {
printf("socket error.");
exit(1);
}
bzero (&server, sizeof ( server ));
server.sin_family=AF_INET;
server.sin_port=htons (PORT);
server.sin_addr.s_addr =htonl (INADDR_ANY);
if(connect (fd, (struct sockaddr *) &server, sizeof(struct sockaddr))==-1){
printf("connect error\n");
exit(1);
}
if ((numbytes=recv(fd,buf,MAXDATASIZE,0))==-1) {
printf("recv error");
exit(1);
}
buf[numbytes]='\0';
printf("server message:%s\n", buf);
close(fd); /* close fd */
}
[/code:1] |
|