Skip to content

Instantly share code, notes, and snippets.

@lanoxx
Created October 20, 2012 17:24
Show Gist options
  • Select an option

  • Save lanoxx/3924104 to your computer and use it in GitHub Desktop.

Select an option

Save lanoxx/3924104 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
int main(int argc, char** argv) {
FILE *file, * filetest;
char *buffer, *filename;
long length;
file = fopen(argv[1], "r");
if(file == NULL) {
perror("File could not be opened");
exit(1);
}
fseek(file,0,SEEK_END);
length = ftell(file);
fseek(file,0,SEEK_SET);
buffer = malloc(length);
if(buffer == NULL) {
perror("Error allocating memory");
exit(1);
}
int i = fread(buffer, length, sizeof(char), file);
printf("fread %ld length %ld, i %d", strlen(buffer), length, i);
fclose(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment