void LogFile(char * p) 

FILE *fp=fopen(fname,"a+"); 
fprintf(fp,"%s",p); //此处需要字符串指针,而不单是字符指针
fclose(fp); 

do { 
strset(strBuffer,' '); 
iResult = recv(s,strBuffer,sizeof(strBuffer),0);//此处所得不是字符串
//可以在此添加一个0使之变为字符串 
LogFile(strBuffer); 
} while( iResult !=0 ); 

解决方案 »

  1.   

    strset的使用是错误的,该函数用来将一个字符串的所有字符设为cExample /* STRSET.C */#include <string.h>
    #include <stdio.h>void main( void )
    {
       char string[] = "Fill the string with something";
       printf( "Before: %s\n", string );
       _strset( string, '*' );
       printf( "After:  %s\n", string );
    }
    OutputBefore: Fill the string with something
    After:  ******************************
      

  2.   

    你的请求头怎么是那样的?不是很标准呀!GET /WinSock/Article/gethostname.htm HTTP/1.0\r\n\r\n
      

  3.   

    1.
    iResult = recv...里的iResult这个参数你怎么没用?
    不应该用fprintf而应该用fwrite,指定长度为iResult
    因为你不能肯定收到的就是字符串,补0则回改变文件的原有面目。2. HTTP协议建议你读一下 RFC
    至少你要下面两行,否则无法做“哄骗DNS解析”,也就是说blueflybird.silversand.net这个地址不告诉服务器,服务器无法知道你要的地址是在blueflybird.silversand.net还是在www.silversand.net,因为他们可能用相同的IP地址!GET /WinSock/Article/gethostname.htm HTTP/1.0\r\n
    Host:blueflybird.silversand.net\r\n 
    \r\n此外,accept-encode/accept-type等也许应该有
      

  4.   

    flywhc
    GET /WinSock/Article/gethostname.htm HTTP/1.0\r\n
    Host:blueflybird.silversand.net\r\n 
    \r\n
    我心里也明白是这个原因
    就是不知要怎么写
    这方面的资料哪里有啊
    或者是说在什么书里面有提到
      

  5.   

    flywhc
    请问一下
    是不是所有的地址都可以用这种方式
    GET /WinSock/Article/gethostname.htm HTTP/1.0\r\n
    Host:blueflybird.silversand.net\r\n 
    \r\n
    比如
    www.csdn.net/expert/topic/149/149257.shtm
    写成
    GET expert/topic/149/149257.shtm HTTP/1.0\r\n
    Host:www.csdn.net\r\n 
    还有请问哪里有这方面的资料查看 
      

  6.   

    官方网站:
    www.ietf.org
    www.ietf.org/rfc/rfc1945.txt HTTP1.0
      

  7.   

    zb_china(zb)
    谢谢你
    看到了
    不过都是英文
    有没有中文的资料
    我的英文程度真的不行