File I/O problem

Hello

Here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <fstream>

using namespace std;

const int EXIT_SUCCESS = 0;
const int EXIT_FAILURE = -1;

int main()
{
    ofstream FileOut("out.txt", ios::app);

    ifstream FileIn("data.txt", ios::in);
    if(!FileIn)
    {
        cerr << "Error in opening file!" << endl;
        return EXIT_FAILURE;
    }

    char line[75];
    int lineCount = 0;

    while(!FileIn.eof())
    {
        FileIn.getline(line, 75, '.');
        FileOut << line << endl;
        lineCount++;
    }

    FileIn.close();
    FileOut.close();

    return EXIT_SUCCESS;
}


My desired output is that if the while loop reads 75 characters first or encounters '.' in the input file(whichever occurs first), then line is stored as:

1 : Whatever text follows.
2 : Whatever text follows.
3 : Whatever text follows.
.
.
.



But this code doesn't seem to be working for me. I'd appreciate any help.
(I've checked that data.txt pre-exists.)

Thanks
Last edited on
what is it not doing?
on a side note, this is going to fail beautifully:
1
2
const int EXIT_SUCCESS = 0;
const int EXIT_FAILURE = -1;
if either iostream or fstream happens to #include, directly or indirectly, stddef.h
@Cubbi


No, its working perfectly. I've had no issues regarding that. When I used EXIT_FAILURE & EXIT_SUCCESS without the statements
1
2
const int EXIT_SUCCESS = 0;
const int EXIT_FAILURE = -1;

then an expected error saying EXIT_FAILURE & EXIT_SUCCESS were not declared pops up.
The issue is that depending on your compiler and library implementation, this program may or may not work. You just happened to have a compiler+library combo where it worked.

All you have to do to make it work 100% of the time is to #include <cstddef> and remove your own EXIT_ definitions.
Topic archived. No new replies allowed.