Advertisement
Nkzlxs

initializeFile v3 Function

Apr 8th, 2020
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. void initializeFiles()
  2. {
  3.     int counter = 0;
  4.     ifstream theFile_1;
  5.  
  6.     //File 1
  7.     theFile_1.open("Employee_Info.txt");
  8.  
  9.     if (theFile_1.is_open())
  10.     {
  11.         //cout << "File 1 is opened" << endl;
  12.  
  13.         //While reading from left to right and the document
  14.         //isn't reaching the end of file
  15.         while (!theFile_1.eof())
  16.         {
  17.             theFile_1 >> col1[counter];
  18.             theFile_1 >> col2[counter];
  19.             theFile_1 >> col3[counter];
  20.             theFile_1 >> col4[counter];
  21.             theFile_1 >> col5[counter];
  22.             theFile_1 >> col6[counter];
  23.             theFile_1 >> col7[counter];
  24.             counter++;
  25.         }
  26.     }
  27.     else
  28.     {
  29.         cout << "File 1 isn't opened" << endl;
  30.     }
  31.     cout << "where is counter now: " << counter << endl;
  32.     for (counter; counter < THE_ARRAY_SIZE; counter++)
  33.     {
  34.         col1[counter] = -1;
  35.         col2[counter] = -1;
  36.         col3[counter] = -1;
  37.         col4[counter] = -1;
  38.         col5[counter] = -1;
  39.         col6[counter] = -1;
  40.         col7[counter] = -1;
  41.     }
  42.  
  43.     //cout << "Debug: col1[0] is " << col1[0] << endl;
  44.     counter = 0;
  45.  
  46.     theFile_1.close();
  47.  
  48.     ifstream theFile_2;
  49.  
  50.     //File 2
  51.     theFile_2.open("Employee_profile.txt");
  52.  
  53.     if (theFile_2.is_open())
  54.     {
  55.         //cout << "File 2 is opened" << endl;
  56.         //While reading from left to right and the document
  57.         //isn't reaching the end of file
  58.         string temp_STR1 = "", temp_STR2 = "";
  59.  
  60.         int met_space = 0;
  61.         while (!theFile_2.eof())
  62.         {
  63.             getline(theFile_2, STR1[counter]);
  64.             getline(theFile_2, STR2[counter]);
  65.             getline(theFile_2, STR3[counter]);
  66.             //cout << STR1[counter] << endl;
  67.             //cout << STR2[counter] << endl;
  68.             getline(theFile_2, STR4[counter]);
  69.             temp_STR1 = "";
  70.             temp_STR2 = "";
  71.             met_space = 0;
  72.             for (int u = 0; u < STR4[counter].length(); u++)
  73.             {
  74.                 if (STR4[counter][u] == ' ')
  75.                 {
  76.                     //if encounter a space then set met_space to 1
  77.                     met_space = 1;
  78.                 }
  79.                 else if (met_space == 0)
  80.                 {
  81.                     temp_STR1 += STR4[counter][u];
  82.                 }
  83.                 else if (met_space == 1)
  84.                 {
  85.                     temp_STR2 += STR4[counter][u];
  86.                 }
  87.             }
  88.             STR4[counter] = temp_STR1;
  89.             STR5[counter] = temp_STR2;
  90.             //cout << STR3[counter] << endl;
  91.             counter++;
  92.         }
  93.     }
  94.     else
  95.     {
  96.         cout << "File 2 isn't opened" << endl;
  97.     }
  98.     cout << "where is counter now: " << counter << endl;
  99.     for (counter; counter < THE_ARRAY_SIZE; counter++)
  100.     {
  101.         STR1[counter] = "";
  102.         STR2[counter] = "";
  103.         STR3[counter] = "";
  104.         STR4[counter] = "";
  105.         STR5[counter] = "";
  106.     }
  107.     //cout << "Debug: STR1[THE_ARRAY_SIZE-1] length is " << STR1[THE_ARRAY_SIZE - 1].length() << endl;
  108.     theFile_2.close();
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement