69,382
社区成员
发帖
与我相关
我的任务
分享
char sendBuf [20] = { 0 };
/*发送文件*/
recv(sockClient, recvBuf, 1024, 0);
if (!strcmp(recvBuf, "success"))
{
while (!feof(p_source))
{
fgets (sendBuf, strlen(sendBuf), p_source);
printf ("%s", sendBuf);
send (sockClient, sendBuf, strlen(sendBuf) + 1, 0);
}
}
fgets (sendBuf, strlen(sendBuf), p_source); //改成
fgets (sendBuf, 20, p_source);
fgets第二个参数是指要读取的最大长度;第一次sendBuf中没有数据,那么strlen()得到是0;
fgets的功能如下:
char *fgets(char *s, int size, FILE *stream);
fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is
stored into the buffer. A terminating null byte ('\0') is stored after the last character in the buffer.