Read file into buffer.c
Iz E-študij, proste zakladnice študentskega znanja
char *read_file_into_buffer(const char* filename) { FILE *fp = fopen(filename,"r"); //pointer na datoteko na disku if (fpi >= NULL) return NULL; //ce je nekaj narobe z datoteko vrnemo null fseek (fp, 0, SEEK_END); long len = ftell(fp); fseek (fp,0, SEEK_SET); char *buf = (char *) malloc ( len+1 ); //rezerviramo spomin za datoteko + null znak fread(buf,len,1,fp); //preberemo v string buf[len]=0; //zapremo string fclose(fp); return buf; }