I'm trying to figure out how to send a file from my server to the client using C. I'm very new at C, so not sure entirely how wrong I have it:
Snippet server:
while (1) { 
    len = sizeof(clientAddr); 
    sock = accept(serverSock, (struct sockaddr *) &clientAddr, &len);
    file = fopen(filename, "rb");
    while(!feof(file)) {
        int flen = fread(buffer, 1, sizeof(buffer), file);
        int sz = 0;
          while (sz < flen) {
            int sent = send(sock, &buffer[sz], flen-sz, 0);
            sz += sent;
          }
        printf("Sent file!");
     }
    fclose(file);
    close(sock);
}
Snippet from Client
int status = connect(sock, (struct sockaddr *)&Address, sizeof(Address));
int flen;
file = fopen(filename, "wb");
while(flen = recv(sock, buffer, sizeof(buffer), 0) > 0) {
    bzero(buffer, sizeof(buffer));
    fwrite(buffer,1, flen, file);
}
Basically, I'm getting an error of "Segmentation Fault (core dump)" from the server. Is there any guide on trying to do this? Any help is appreciated, thanks!
