I need to read a file and then send it through a socket, but fread crash for some reason. Any idea?
//Get file length
fseek(fd, 0, SEEK_END);
int fileLen=ftell(fd);
fseek(fd, 0, SEEK_SET);
//Allocate memory
buf=(char *)malloc(fileLen+1)* sizeof(char));
if (!buf)
{
fprintf(stderr, "Memory error!");
}
rewind(fd);
fread((void *)buf, strlen(buf)+1, 1, fd);