Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* File::read_all(){
- char* text = NULL;
- if (file != NULL) {
- fseek(file, 0, SEEK_END);
- int count = ftell(file);
- //rewind();
- //printf("File is %i bytes long\n", count);
- fseek(file, 0, SEEK_SET);
- if (count > 0){
- //text = (char*)malloc(sizeof(char) * (count + 1));
- text = new char[count+1];
- //printf("%p\n", text);
- if(text == NULL){
- printf("Couldn't create text array\n");
- exit(-1);
- }
- count = fread((void*)text, sizeof(char), count, file);
- //printf("Read %i bytes\n", fread(text, sizeof(char), count, file));
- text[count+1] = '\0';
- return text;
- }else{
- printf("File empty\n");
- return NULL;
- }
- //fclose(file);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement