Could you help me?

Hello all,

I'm new to the language C++. Recently our teacher asked us to write a code
that does the following things:

1 - Remove all comments from a file (only comments starting with //).
2 - 'Jump' correctly.
3 - Find out if a certain number is a Lychrel number.
4 - Include statistics (how many lines/characters does the input file have?)

It has to behave like a compiler, so to say. We have to use functions to achieve these goals and we may only use <iostream>, <fstream>, <string>, and <climits>.

Now I'm facing one big problem. I'm writing a function that counts how many lines the input file has, but it just doesn't work.
I don't get any errors, but when I run the program, I get (for teller) 0.
If I remove the 0 from the code (see below for the code) I get the result 2147344384. That obviously is incorrect.

Here below you can find the code. This is my attempt to count how many times a person pressed 'Enter' to continue on a new line.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int telRegels (ifstream& invoer)
{   int teller;
    char B = invoer.get ();
    char A = '\n';
    int C = static_cast<int>(B);
    while (! invoer.eof())
    {     if (C == 13)
           {teller++;
           }
          A = B;
          B = invoer.get ();
    }
    return teller;
}


   cout << telRegels (invoer);


Could you guys help me?

Kind regards,

NSA
Topic archived. No new replies allowed.