Yurttas/PL/OOL/Cplusplus/F/06/01/io 11.cpp

Revision as of 22:50, 6 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="cpp" line start="1" enclose="div">/* Copyright(C) 1998 All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. Perm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 1/*
 2   Copyright(C) 1998
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 1998.
11   author : Salih Yurttas.
12
13   io_11.cpp
14*/
15
16
17#include <iostream>
18
19#include <fstream>
20
21using namespace std;
22
23void double_space(ifstream& i_f,
24                  ofstream& o_f) {
25  char c;
26
27  while(i_f.get(c)) {
28    o_f.put(c);
29    if(c=='\n') 
30      o_f.put(c);
31  }
32}
33
34
35int main(int argc, char* argv[]) {
36
37  if(argc != 3 ) {
38    cout << "\nUsage: " << argv[0]
39         << " infile outfile\n";
40    exit(1);
41  }
42
43  ifstream f_in;
44  ofstream f_out;
45
46  f_in.open(argv[1], ios::in);
47  f_out.open(argv[2], ios::out);
48
49  if(!f_in) {
50    cerr << "cannot open " << argv[1];
51    exit(1);
52  }
53
54  if(!f_out) {
55    cerr << "cannot open " << argv[2];
56    exit(1);
57  }
58
59  double_space(f_in,
60               f_out);
61
62  f_in.close();
63  f_out.close();
64
65}