运行报错,,在网上一搜,说是最后没有打空格,在最后也敲了空格了,怎么又报错了,求指点?

tb_engineer 发布于 2014/09/08 19:02
阅读 96
收藏 0
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>    // for sockaddr_in
#include <sys/types.h>    // for socket
#include <sys/socket.h>    // for socket
#include <stdio.h>        // for printf
#include <stdlib.h>        // for exit
#include <string.h>        // for bzero
#include <time.h>                //for time_t and time


#define CLIENT_PORT 1234
#define MAX 1024


char *IP="127.0.0.1";
int client_socket;
int ret;
int my;


int main()
{
  client_socket =socket(AF_INET,SOCK_STREAM,0);
  if(-1 == client_socket)
{
perror("sosck failed\n");
exit(-1);
}
struct sockaddr_in client_addr;
client_addr.sin_family =AF_INET;
client_addr.sin_port =htons(CLIENT_PORT);
client_addr.sin_addr.s_addr = inet_addr(IP);


ret =connetct(client_socket, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
if(-1 == ret)
{
perror("connetct failed\n");
exit(-1);
}

while(1)
{
    FILE *stream;
 char buf[MAX]="hello 服务器";
    strcat(buf,"发送请求");


 if(-1 == send(client_socket,buf,sizeof(buf)+1,0))
 {
   perror("send failed\n");
   exit(-1);
 }
ret =recv(client_socket,buf,1024,0);
 if(-1 ==ret)
  {
   perror("recv failed\n");
      exit(-1);
  }
  if(fopen("file2","w+") == NULL)
   {
    printf("the file open error\n");
   exit(-1);
   }
  else
  {
  printf("the file open successful\n");
 }
 printf("Send %s\n",buf);
   int lengsize = 0;
   if(lengsize=fwrite(buf,1,1024,stream) == -1)
   {
     printf("lengsize = %d\n",lengsize);
     if(send(client_socket,buf,lengsize,0)<0)
     {
  printf("Send File is Failed\n");
  break;
   }
    bzero(buf, 1024);
    if(fclose(stream))
      {
       printf("The file 'data' was not closed! \n");
       exit(1);  
   } 
}   
 close(client_socket);    
   return 0;
   
   
   
}


加载中
0
DavidWTF
DavidWTF
你用的什么编辑器写代码?{}不配对就不给你提示吗?
tb_engineer
tb_engineer
回复 @tb_engineer : 你说的很对,细心真的很重要,对程序员来说,谢谢了,万分感谢。
tb_engineer
tb_engineer
回复 @DavidWTF :没有粘了一个}
DavidWTF
DavidWTF
回复 @tb_engineer : 那就不知道了,你帖的代码上一共11个{,10个},不信自己数数。细心是程序员的第一要求.
tb_engineer
tb_engineer
回复 @DavidWTF : 不对,不是少}的问题,
DavidWTF
DavidWTF
回复 @tb_engineer : 怪不得,最后少个}
下一页
返回顶部
顶部