Advertisement
Domerk

Открытие файла

Oct 26th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <windows.h>
  6. #include "functions_bridge.h"
  7.  
  8.  
  9.  
  10. int main ()
  11. {
  12.     int i;
  13.     char i_char[10];
  14.    
  15.     CreateDirectory("D:\\BD_bridge", NULL);
  16.  
  17.     FILE *file;
  18.     char* file_name = "D:\\BD_bridge\db_bridge.dat";
  19.  
  20.     file = fopen (file_name, "rb");
  21.     if(file == NULL)
  22.     {
  23.         file = fopen(file_name, "w+b" );
  24.     }
  25.     else
  26.     {
  27.         std::cout<<"  Database file exists, create new?"<<endl<<"  1 - Yes"<<endl<<"  2 - No"<<endl;
  28.         std::cin>>i;
  29.         if (i==1)
  30.         {
  31.             char* str = ".dat";
  32.             char file_name2 [50] = "D:\\BD_bridge\db_bridge";
  33.  
  34.             std::cout<<"  Select the number of new database"<<endl;
  35.             std::cin>>i;
  36.            
  37.             strcat(file_name2, itoa(i, i_char, 10));
  38.             strcat(file_name2, str);
  39.             file_name = file_name2;
  40.             file = fopen(file_name, "w+b" );
  41.         }
  42.     }
  43.  
  44.     fclose (file);
  45.  
  46.     i = 1;
  47.  
  48.     while (i != 5)
  49.     {
  50.         std::cout<<endl<<"  Menu:"<<endl;
  51.         std::cout<<"  1 - Creat"<<endl<<"  2 - Review"<<endl<<"  3 - Sorting"<<endl<<"  4 - Search"<<endl<<"  5 - Exit"<<endl;
  52.         std::cin>>i;
  53.  
  54.         switch (i)
  55.         {
  56.         case 1: Create (file, file_name); break;
  57.         case 2: Review (file, file_name); break;
  58.         case 3: Sorting (file, file_name); break;
  59.         case 4: Search (file, file_name); break;
  60.         case 5: std::cout<<endl<<"  The End! :) "<<endl; break;
  61.         }
  62.  
  63.     }
  64.  
  65.     std::cin.sync();
  66.     std::cin.get();
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement