开发者社区> 问答> 正文

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

#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;
   
   
   
}


展开
收起
爱吃鱼的程序员 2020-06-14 21:57:14 476 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

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

    2020-06-14 21:57:30
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载