Your logic of writing upto *pt != '\0'
is not correct in this loop
while((c=*pt)!='\0')
{
fwrite(&c, sizeof(c),1, fp);
pt++;;
}
There can be '\0'
character anywhere in the binary data of .png file. So you will not write data after that, hence you are seeing your file size smaller than file size on server.
You should parse the HTTP headers and get value for Content-Length
, which gives size of data in bytes and read those many from server and write in local file.
Look for HTTP RFC for more details about the protocol.
There are other problems in your code like
char *pt=malloc(100000);
pt=strstr(rep,"\r\n\r\n");
With this malloc()
to pt
is not required and leaks the memory.