Problem in File seek()
-
Hi All, I am reading some big files having thousands of lines, my requirement is to write some thing on the last but one line(i know the length of last line). how to seek my file pointer to last but one line with out seeking all the position from the beginning of the file? i tried with some code, but not achieving the right goal. please check the code
long seekval = assfile.SeekToEnd(); assfile.Seek((seekval - 4.0),0); assfile.WriteString(\_T("some text"));
assfile is the CStdioFile obj. 4 is the length of the last line. Thanks in advance. Regards, Kumar
-
Hi All, I am reading some big files having thousands of lines, my requirement is to write some thing on the last but one line(i know the length of last line). how to seek my file pointer to last but one line with out seeking all the position from the beginning of the file? i tried with some code, but not achieving the right goal. please check the code
long seekval = assfile.SeekToEnd(); assfile.Seek((seekval - 4.0),0); assfile.WriteString(\_T("some text"));
assfile is the CStdioFile obj. 4 is the length of the last line. Thanks in advance. Regards, Kumar
-
Hi All, I am reading some big files having thousands of lines, my requirement is to write some thing on the last but one line(i know the length of last line). how to seek my file pointer to last but one line with out seeking all the position from the beginning of the file? i tried with some code, but not achieving the right goal. please check the code
long seekval = assfile.SeekToEnd(); assfile.Seek((seekval - 4.0),0); assfile.WriteString(\_T("some text"));
assfile is the CStdioFile obj. 4 is the length of the last line. Thanks in advance. Regards, Kumar
Read the content of the file, modify what you need, write the file back. You cannot modify a line directly in a text file.
SkyWalker
-
Hi All, I am reading some big files having thousands of lines, my requirement is to write some thing on the last but one line(i know the length of last line). how to seek my file pointer to last but one line with out seeking all the position from the beginning of the file? i tried with some code, but not achieving the right goal. please check the code
long seekval = assfile.SeekToEnd(); assfile.Seek((seekval - 4.0),0); assfile.WriteString(\_T("some text"));
assfile is the CStdioFile obj. 4 is the length of the last line. Thanks in advance. Regards, Kumar
If you are using CFile, then the second parameter for the
Seek()
method is from where to seek. In your case you should seek from the end of the file, usingCFile::end
. In your code, you are seeking from the beginning of the file. --modification-- Sorry, Richard MacCutchan had already answered the question. Ignore mine, please! -
Read the content of the file, modify what you need, write the file back. You cannot modify a line directly in a text file.
SkyWalker
Are you sure about that? My memory - not that I've done file handling in the last 4 or 5 years - says that you can modify whatever you want, you just can't add any characters or take away any characters (so you can't add a line of text to a text file, but you can change "Paul" to "Fred".
-
Hi All, I am reading some big files having thousands of lines, my requirement is to write some thing on the last but one line(i know the length of last line). how to seek my file pointer to last but one line with out seeking all the position from the beginning of the file? i tried with some code, but not achieving the right goal. please check the code
long seekval = assfile.SeekToEnd(); assfile.Seek((seekval - 4.0),0); assfile.WriteString(\_T("some text"));
assfile is the CStdioFile obj. 4 is the length of the last line. Thanks in advance. Regards, Kumar
First Read the last line Move this line by the length of line you want to add in front. Then paste the required line above it I hope this will do
ashwani