D
dbuser
Hi,
I need help on a problem, as described below. I am reading a file
"input.txt"which has data like this:
abc def gh izk lmnopq rst uvwxyz
I am using fstream object to read the file and writing into a dynamic
array. My problem is that the array shows extra z and probably because
of this further processing gives run time error in borland compiler.
Can you please tell me, if the problem is related to handling end-of
line , how do i do it.
here is the piece of code I am using:
char ch;
char * input;
input = new char[size]; // size is determined at runtime
memset(input, 0, sizeof(input));
ifstream infile("input.txt", ios::in);
if(!infile) cerr << "Error opening file" << endl;
while(!infile.eof()){
infile.get(ch);
input = ch;
i++;
}
cout << input << endl;
infile.close();
as you can see, the output shows extra 'z'
abc def gh izk lmnopq rst uvwxyzz
Thanks for any help!
regards!
dbuser
I need help on a problem, as described below. I am reading a file
"input.txt"which has data like this:
abc def gh izk lmnopq rst uvwxyz
I am using fstream object to read the file and writing into a dynamic
array. My problem is that the array shows extra z and probably because
of this further processing gives run time error in borland compiler.
Can you please tell me, if the problem is related to handling end-of
line , how do i do it.
here is the piece of code I am using:
char ch;
char * input;
input = new char[size]; // size is determined at runtime
memset(input, 0, sizeof(input));
ifstream infile("input.txt", ios::in);
if(!infile) cerr << "Error opening file" << endl;
while(!infile.eof()){
infile.get(ch);
input = ch;
i++;
}
cout << input << endl;
infile.close();
as you can see, the output shows extra 'z'
abc def gh izk lmnopq rst uvwxyzz
Thanks for any help!
regards!
dbuser