Thursday, 15 August 2013

Difference between fgets and fread

Difference between fgets and fread

I have the following code below:
#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;
}
When I use fgets, it truncates the data displayed. But when I use fread ,
it displays all the content. By the way, this is the cgi script for an
html file upload using post method. Any help would be greatly aprreciated.

No comments:

Post a Comment