|

楼主 |
发表于 2004-3-4 09:21:07
|
显示全部楼层
已经解决了,我把过程贴在这里
1)把源文件名改为.c
2)出现for循环错误,是因为c和c++里面对for循环定义的不同
在c语言里,函数里用到的变量要在函数前面定义.你在for循环里定义了int i,所以不对,放到前面定义就好了.
c++语言可以这样的.
- while (num = recv(connectfd, recvbuf, MAXDATASIZE,0))
- {
- recvbuf[num] = '\0';
- printf("Received client( %s ) message: %s",cli_name, recvbuf);
- for (int i = 0; i < num - 1; i++)
- {
- sendbuf[i] = recvbuf[num - i -2];
- }
- sendbuf[num - 1] = '\0';
- send(connectfd,sendbuf,strlen(sendbuf),0);
- }
- close(connectfd);
复制代码 |
|