0
void RecvFile() 
{ 
int rval; 
char buf[0x1000]; 
FILE *file = fopen("C:\\pic.bmp", "wb"); 
if (!file)
{
    printf("Can't open file for writing");
    return;
}

do
{
    rval = recv(winsock, buf, sizeof(buf), 0);
    if (rval < 0)
    {
        // if the socket is non-blocking, then check
        // the socket error for WSAEWOULDBLOCK/EAGAIN
        // (depending on platform) and if true then
        // use select() to wait for a small period of
        // time to see if the socket becomes readable
        // again before failing the transfer...

        printf("Can't read from socket");
        fclose(file);
        return;
    }

    if (rval == 0)                 
        break; //line 159

    int off = 0;
    do
    {
        int written = fwrite(&buf[off], 1, rval - off, file);
        if (written < 1)
        {
            printf("Can't write to file");
            fclose(file);
            return;
        }

        off += written;
    }
    while (off < rval)
} //line 175

fclose(file); 
}

'}' 标记之前的 175 语法错误
159 被早期错误混淆,退出

我不知道该怎么办...你能帮帮我吗?我在 c 编程方面还是个新手。我在代码中插入了错误行。我不明白为什么会出现这个错误......你们能解释一下为什么吗?

4

4 回答 4

2

实际上你;在while循环中丢失了

while (off < rval);   // 174 line
                  ^

第二个外循环没有while

do{

}// 175 line
while()  // this is missing ???

我不是 100% 确定但我认为你需要在外部无限循环(下面的粗略代码)阅读评论:

do{

   // rev = recv(....
   if(rev <){
    // you return from here that is reason i believe you need infinite loop 
    // code
   }
   //code
   do{
       // your code
   }while (off < rval); // at like 174
}while(1); // line 175
于 2013-03-03T14:50:20.197 回答
0

有2个错误。

  1. while (off < rval)应该替换为while (off < rval);
  2. 您缺少while第一个声明do
于 2013-03-03T14:53:08.017 回答
0

在第 175 行,您应该有一个while语句,因为您在开头有一个相应的 do 语句。代码中的另一个 do-while 语句也缺少分号。

void RecvFile() 
{ 
int rval; 
char buf[0x1000]; 
FILE *file = fopen("C:\\pic.bmp", "wb"); 
if (!file)
{
    printf("Can't open file for writing");
    return;
}

do //******Where is the while for this do statement?*****
{
    rval = recv(winsock, buf, sizeof(buf), 0);
    if (rval < 0)
    {
        // if the socket is non-blocking, then check
        // the socket error for WSAEWOULDBLOCK/EAGAIN
        // (depending on platform) and if true then
        // use select() to wait for a small period of
        // time to see if the socket becomes readable
        // again before failing the transfer...

        printf("Can't read from socket");
        fclose(file);
        return;
    }

    if (rval == 0)                 
        break; //line 159

    int off = 0;
    do
    {
        int written = fwrite(&buf[off], 1, rval - off, file);
        if (written < 1)
        {
            printf("Can't write to file");
            fclose(file);
            return;
        }

        off += written;
    }
    while (off < rval) // *** A semicolon is needed here ***
} //line 175

fclose(file); 
}
于 2013-03-03T14:50:33.413 回答
0

您忘记了do...while块后的分号

改变

while (off < rval)while (off < rval);

于 2013-03-03T14:51:03.907 回答