Link to home
Start Free TrialLog in
Avatar of riteshromi
riteshromi

asked on

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>

THIS IS IN C++ AND I AM NOT USING MFC

HOW TO MOVE THE END OF FILE TO A DESIRED LOCATION
Avatar of Prashant Sabnekar
Prashant Sabnekar
Flag of India image

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()

Regards
Prashant Sabnekar
Avatar of riteshromi
riteshromi

ASKER

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
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,
Ritesh
ASKER CERTIFIED SOLUTION
Avatar of wayside
wayside

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial