reading strings
Mar 10, 2017 at 10:23pm Mar 10, 2017 at 10:23pm UTC
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:
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!
Mar 10, 2017 at 11:08pm Mar 10, 2017 at 11:08pm UTC
Last edited on Mar 10, 2017 at 11:08pm Mar 10, 2017 at 11:08pm UTC
Topic archived. No new replies allowed.