Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <cstdlib>
- #include <fstream>
- #include <iostream>
- using namespace std;
- bool rw(char *f_io, int *oi_mas, bool flag);
- void i_f(int *mas, int *o_mas, int el);
- int main() {
- char f_in[128];
- char f_out[128];
- cout << "Enter a name Input file: " << endl;
- cin >> f_in;
- cout << "Enter a name Output file: " << endl;
- cin >> f_out;
- int *mas = new int[64];
- int *o_mas = new int[64];
- if (rw(f_in, mas, 1)) {
- cout << "Enter a value Element:" << endl;
- int element;
- cin >> element;
- i_f(mas, o_mas, element);
- rw(f_out, o_mas, 0);
- }
- return 0;
- }
- void i_f(int *mas, int *o_mas, int el) {
- int n = 0;
- int i = 0;
- while (mas[i] != '\0') {
- if (el==mas[i]) {
- o_mas[n] = i + 1;
- n++;
- }
- i++;
- }
- o_mas[n] = '\0';
- }
- bool rw(char *f_io, int *oi_mas, bool flag) {
- int n = 0;
- if (flag) {
- ifstream fin(f_io);
- if (fin) {
- while (!fin.eof()) {
- fin >> oi_mas[n];
- n++;
- }
- oi_mas[n] = '\0';
- fin.close();
- return 1;
- }
- else cout << "ERROR: DON'T OPEN " << f_io << "!" << endl; return 0;
- }
- else {
- ofstream fout(f_io);
- if (fout) {
- int i = 0;
- while (oi_mas[i] != '\0') {
- fout << oi_mas[i] << " ";
- i++;
- }
- return 1;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement