我有以下代码:
下面是代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int lendata;
printf("Content-type:text/html\n\n");
printf("<html><body>");
lendata = atoi(getenv("CONTENT_LENGTH"));
char *buf = malloc(lendata+1);
fread(buf,lendata,1,stdin);
printf("%s\n<br>",buf);
printf("%d",lendata);
free(buf);
printf("</body></html>");
return 0;
}
当我使用fgets
时,它会截断显示的数据。但是当我使用fread
时,它会显示所有内容。顺便说一下,这是使用POST方法上传HTML文件的CGI脚本。非常感谢您的帮助。
char buffer[ buff_len ];
替代吗?(没有 *)。顺便说一下:在fread( ( void * )buffer
中,( void * )
是多余的。 - chux - Reinstate Monicavoid
转换,所以我还是加上了,因为我知道无论如何都不会有害。但你说得很对。 - Jacob Pollackfread(buffer, sizeof(buffer[0]), sizeof(buffer)/sizeof(buffer[0]), stdin)
这种方式,因为它可以很好地适应重新编辑的foo_type buffer[foo_N]
。 - chux - Reinstate Monica