Advertisement
Usow_Maxim

FileRead v.1

Aug 3rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. char** FileRead(char fileName[], int &Size, bool &success)
  2. {
  3.     FILE* f = fopen(fileName, "r");
  4.     Size = 0;
  5.     char buf[1000];
  6.     char** str = NULL;
  7.     char* estr;
  8.     if(f == NULL)
  9.     {
  10.         printf("Ошибка открытия файла!\n");
  11.         success = false;
  12.     }
  13.     else
  14.     {
  15.         printf("Началось чтение из файла\n");
  16.         while(1)
  17.         {
  18.             estr = fgets (buf, sizeof(buf), f);
  19.             if (estr == NULL)
  20.             {
  21.                 if ( feof (f) != 0)
  22.                 {
  23.                     printf ("\nЧтение файла закончено\n");
  24.                     break;
  25.                 }
  26.                 else
  27.                 {
  28.                     printf ("\nОшибка чтения из файла\n");
  29.                     success = false;
  30.                     break;
  31.                 }
  32.             }
  33.             str = AddString(str, Size, buf);
  34.         }
  35.         printf ("Закрытие файла: ");
  36.         if ( fclose (f) == EOF)
  37.         {
  38.             printf ("ошибка\n");
  39.             success = false;
  40.         }
  41.         else
  42.             printf ("выполнено\n");
  43.     }
  44.     delete[] estr;
  45.     return str;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement