Advertisement
JewishCat

odmas_7v

May 3rd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <cstdlib>
  3. #include <fstream>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. bool rw(char *f_io, int *oi_mas, bool flag);
  9. void i_f(int *mas, int *o_mas, int el);
  10.  
  11. int main() {
  12.  
  13.  
  14.     char f_in[128];
  15.     char f_out[128];
  16.     cout << "Enter a name Input file: " << endl;
  17.     cin >> f_in;
  18.     cout << "Enter a name Output file: " << endl;
  19.     cin >> f_out;
  20.     int *mas = new int[64];
  21.     int *o_mas = new int[64];
  22.     if (rw(f_in, mas, 1)) {
  23.         cout << "Enter a value Element:" << endl;
  24.         int element;
  25.         cin >> element;
  26.         i_f(mas, o_mas, element);
  27.         rw(f_out, o_mas, 0);
  28.     }
  29.  
  30.     return 0;
  31. }
  32. void i_f(int *mas, int *o_mas, int el) {
  33.     int n = 0;
  34.     int i = 0;
  35.     while (mas[i] != '\0') {
  36.         if (el==mas[i]) {
  37.             o_mas[n] = i + 1;
  38.             n++;
  39.         }
  40.         i++;
  41.     }
  42.     o_mas[n] = '\0';
  43. }
  44.  
  45. bool rw(char *f_io, int *oi_mas, bool flag) {
  46.     int n = 0;
  47.     if (flag) {
  48.         ifstream fin(f_io);
  49.         if (fin) {
  50.             while (!fin.eof()) {
  51.                 fin >> oi_mas[n];
  52.                 n++;
  53.             }
  54.             oi_mas[n] = '\0';
  55.             fin.close();
  56.             return 1;
  57.         }
  58.         else cout << "ERROR: DON'T OPEN " << f_io << "!" << endl; return 0;
  59.     }
  60.     else {
  61.         ofstream fout(f_io);
  62.         if (fout) {
  63.             int i = 0;
  64.             while (oi_mas[i] != '\0') {
  65.                 fout << oi_mas[i] << " ";
  66.                 i++;
  67.             }
  68.             return 1;
  69.         }
  70.     }
  71.     return 1;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement