Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created November 2, 2012 20:50
Show Gist options
  • Save AlexFrazer/4004228 to your computer and use it in GitHub Desktop.
Save AlexFrazer/4004228 to your computer and use it in GitHub Desktop.
file reader
/*
* reads files
* @Alex "Crowz" Frazer
*/
#include <stdio.h>
#include <string.h>
#define OK 0
#define FILE_NOT_FOUND -1
FILE *file;
int main() {
}
char * asciiread(char *filename) {
char * contents;
file=fopen(filename);
if(filename==NULL) {
printf("error: file not found");
return FILE_NOT_FOUND;
}
fseek(file, 0L, SEEK_END);
int size=ftell(file);
fseek(file, 0L, SEEK_SET);
contents=(char *)malloc(size*sizeof(char));
return contents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment