reading strings

I don't understand the logic of program below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("file.in");
ofstream fout("file.out");
char a[100][100],n;
int main()
{
    int i=0,nr=0;
    fin>>n;
    fin.get();
    for(i=1;i<=n;i++)
    {
        fin.get(a[i],100);
        fin.get();
        nr++;
    }
    fout<<nr;
    return 0;
}

The input consists of this:
1
2
3
4
3
aa
bb
cc

and this is why the number of passing through the for loop was supposed to be 3, but when I run the program, it gives me 51!! Can you please explain me what's wrong with it? Thanks in advance!
n is a char.
char 3 is not 3.
char 3 is .... well, take a guess :)
http://www.asciitable.com/
Last edited on
Topic archived. No new replies allowed.