Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. char* File::read_all(){
  2.     char* text = NULL;
  3.  
  4.  
  5.     if (file != NULL) {
  6.         fseek(file, 0, SEEK_END);
  7.         int count = ftell(file);
  8.         //rewind();
  9.         //printf("File is %i bytes long\n", count);
  10.         fseek(file, 0, SEEK_SET);
  11.  
  12.         if (count > 0){
  13.             //text = (char*)malloc(sizeof(char) * (count + 1));
  14.             text = new char[count+1];
  15.             //printf("%p\n", text);
  16.             if(text == NULL){
  17.                 printf("Couldn't create text array\n");
  18.                 exit(-1);
  19.             }
  20.             count = fread((void*)text, sizeof(char), count, file);
  21.             //printf("Read %i bytes\n", fread(text, sizeof(char), count, file));
  22.             text[count+1] = '\0';
  23.             return text;
  24.         }else{
  25.             printf("File empty\n");
  26.             return NULL;
  27.         }
  28.         //fclose(file);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement