How can we move the end of file to a specified location in c++ not using MFC

suppose there is a file x and a delta file y. the final file is x and the size is fixed to 10000 lines. In file x the line end with a carriage return. I want to prepend the file y to x and if the resulting file is greater than 10000 lines I want to remove the lines from 10000 onwards. If someone could tell me how to move the END OF FILE to a desired location, I would appreciate that.
for counting the number of line I am using the command
find /v /c "noshuchstring" <file name>


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prashant SabnekarAVPCommented:
In C
#include <stdio.h> provides functions like fseek(), lseek(), rewind(), ... to move the file offset to desired location.
In C++
#include <fstream.h> provides functions like.
seekg(), seekp()

Prashant Sabnekar
riteshromiAuthor Commented:
I dont want the file pointer to be moved. If I am using the file pointer my cpu utilizes to 100% and I do not want that. I want to just truncate the number of lines from the bottom of file x. The number of lines to be truncated is equal to the number of lines in y
riteshromiAuthor Commented:
If I could move my end of file to a specified location, I would not need to count the number of lines and then delete. If the end of file is moved it marks the end of file... thanks,
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Are all the lines in the file exactly the same length?

If not, there is no way to know where to move the EOF marker without reading each line along the way, because the file has no concept of lines; this is structure imposed at a higher level by arbitrarily picking a character to mark the end of a line.

If each line is exactly the same  size you can easily calculate how many bytes 10,000 lines takes up, and use _chsize() or _chsize_s() to truncate the file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
riteshromiAuthor Commented:
no each line does not have the same size. I am trying to have the file x in memory as a circular file and then when needed create a new file with y prepended. But I think with this also the CPU will sipke to 100%. not sure wat to do
Prashant SabnekarAVPCommented:
To move the eof to a desired location, simply delete the contents after that line.
1. copy file in some temp file.
2. delete ur file, or open it freshly, not in append mode.
3. copy ur temp file into ur file.

Prashant Sabnekar
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.