Wednesday, November 18, 2009

VC++ File Handling : Reading File from Particular Position Using Seek( ) Function





void CFile1Dlg::OnWrite()

{

// TODO: Add extra validation here

UpdateData();
CFile cf;
char ch[100];
cf.Open("d://aits.txt",CFile::modeCreateCFile::modeWrite);
strcpy(ch,m_edit1);
cf.Write(ch,m_edit1.GetLength());
cf.Close();
m_edit1="";
UpdateData(FALSE);


}

void CFile1Dlg::OnRead()
{

// TODO: Add your control notification handler code here
UpdateData();
if(m_pos1==0)
{
MessageBox("please enter position other wise start reading from begining of file");
}

pos=m_pos1;

CFile cf;
char ch[100];
cf.Open("d://aits.txt",CFile::modeRead);

cf.SeekToBegin();
cf.Seek(pos,CFile::begin);
cf.Read(ch,cf.GetLength());

m_edit1="";
for(unsigned int i=0;i

{
m_edit1+=ch[i];
}

cf.Close();
UpdateData(FALSE);
}

No comments:

Post a Comment