[ create a new paste ] login | about

Link: http://codepad.org/kRotkDew    [ raw code | fork ]

C, pasted on Oct 14:
#include <stdio.h>
#include <stdlib.h>

static void read_file_print(const char* path)
{
    FILE* fp;
    size_t read_size = 0, file_size;
    char* read_buf;

    if ((fp = fopen(path, "r")) < 0) return;

    fseek(fp, 0, SEEK_END);
    file_size = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    read_buf = malloc(file_size);

    while (fread(read_buf, 1, 128, fp) > 0) ;

    printf("%s", read_buf);

    free(read_buf);
}

int main(int argc, char* argv[])
{
    if (argc < 2) return 0;

    read_file_print(argv[1]);

    return 0;
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: