hi,need some help on my simple program.
i have 3 txt files,
file2 is the source file and its constantly adding lines from others program. file1 is the temp file for compare.
file3 is the different between file 1 and file 2.
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main () {
while (true)
{
int length, length2;
char * buffer;
ifstream is, is2;
FILE * pFile;
1. use std::ifstream for your input files.
2. Use std::ofstream for your output file.
3. Don't call open/close on streams.
4. Declare variables where you use them.
5. Don't try to read the file by seeking to the end and all the stuff. It only works for small files. Instead read sections at a time and add to some buffer until you've read all the file.
Once you've done all that you'll be able to clearly see what you're doing. You're constantly overwriting file2.txt. At the end of the loop, it always has the content of file1.txt.
kbw, tks for the replied.
beside using the buffer to read file1, what other method you recommend to read file1? file1 will eventually will gets up to 10mb or more. what is the fastest way to read?
for ex:
at 9:00am
1. file1 has 10 lines
2. file2 has 0 lines
3. copy 10 lines from file1 to file3
4. copy file1 to file2
.......
at 3:30pm
1 file1 has 1000000 lines
2.file2 has 800000 lines
3.seek line to line # 800001 from file1
4.copy from 800001 to 1000000 from file1 to file3
5.copy file1 to file2
......
file3 must be updated within a short period of time like in 'seconds' because a third program will constantly monitor it.
please advise how to approach for this program, tks.