Hello,
The pgm below opens a file, reads it and displays the contents and its length.
However it displays a length of (length+2) and also the samplesread as (samplesread +2), where samplesread is the length obtaines from gcount(), and length from tellg(). Pls tell me how i should get the correct length and samplesread??. Also if i enter the data in my file in the next line, it considers "\n" towards the length count. Pls correct my code.
Thanks,
Prads
[code=cpp]
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int length,samplesr ead,blksize=30;
char *rawsignal;
ifstream acq_data; //acq_data is the fid
acq_data.open ("C:\\t1\\p.bin ", ios::binary);
acq_data.seekg (0, ios::end);
length = acq_data.tellg( ); // check this out
acq_data.seekg (0, ios::beg);
rawsignal= new char [length];
acq_data.read (rawsignal,leng th);
samplesread=acq _data.gcount(); // check this out
cout<<"the length is"<<length<<en dl;
cout<<"the number of samples read is"<<samplesrea d<<endl;
acq_data.close( );
cout.write (rawsignal,leng th);
delete[] rawsignal;
getchar();
return 0;
}
[/code]
The pgm below opens a file, reads it and displays the contents and its length.
However it displays a length of (length+2) and also the samplesread as (samplesread +2), where samplesread is the length obtaines from gcount(), and length from tellg(). Pls tell me how i should get the correct length and samplesread??. Also if i enter the data in my file in the next line, it considers "\n" towards the length count. Pls correct my code.
Thanks,
Prads
[code=cpp]
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int length,samplesr ead,blksize=30;
char *rawsignal;
ifstream acq_data; //acq_data is the fid
acq_data.open ("C:\\t1\\p.bin ", ios::binary);
acq_data.seekg (0, ios::end);
length = acq_data.tellg( ); // check this out
acq_data.seekg (0, ios::beg);
rawsignal= new char [length];
acq_data.read (rawsignal,leng th);
samplesread=acq _data.gcount(); // check this out
cout<<"the length is"<<length<<en dl;
cout<<"the number of samples read is"<<samplesrea d<<endl;
acq_data.close( );
cout.write (rawsignal,leng th);
delete[] rawsignal;
getchar();
return 0;
}
[/code]
Comment