you might also look into using
fseek(script, 0, SEEK_END); // position to the end of the file
size = ftell(script); // get the file size
fseek(script, 0, SEEK_SET); // rewind to the beginning of the file
code = malloc(sizeof(char)*(size+1));
if(code) {
fread(code, sizeof(char), size, script);
code[size] = '\0';
}
with some additional error checking