F
F
flashdix2016-06-11 11:36:14
C++ / C#
flashdix, 2016-06-11 11:36:14

How to download n bytes of a remote file in ANSI C?

Please let me know how the function should work. Google didn't help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maaGames, 2016-06-11
@maaGames

cURL.

J
jcmvbkbc, 2016-06-13
@jcmvbkbc

size_t read_from_url(const char *url, char *buf, size_t sz)
{
    char *cmd = malloc(strlen(url) + 13);
    FILE *f;
    size_t off = 0;

    sprintf(cmd, "wget -O - '%s'", url);
    f = popen(cmd, "r");
    free(cmd);

    while (sz) {
        size_t rd = fread(buf + off, 1, sz, f);

        if (rd == 0)
            break;
        off += rd;
        sz -= rd;
    }
    pclose(f);
    return off;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question