Hello,
For some reason i need to append new data
(text line,every few minutes) to log file at start. What is proper way to do this . I'm using Dev-C , winapi.
Thanks and regards,
stefan
Hello,
For some reason i need to append new data
(text line,every few minutes) to log file at start. What is proper way to do this . I'm using Dev-C , winapi.
Thanks and regards,
stefan
Write out your new data to a new file
Append the old file onto the end of the new file
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
hello,Salem,
1)'Movefile' old log file to temporary name
2)'createfile' new logfile , write new data
3)''createfle' for reading from renamed old file
4)'readfile' oldfile, 'writefile' into new file loop.
I see this way, but in case of very long file - this can be wrong way, i hesitate.
regards
What is the point of putting new data at the start of a file every few minutes?
Most people append to the END of a file, because it is a really simple thing to do.
How often do you READ the log file - once per day perhaps?
If writing is frequent (a few minutes) and reading is rare (once a day), then consider appending the data to the end of the log file, then figure out some kind of "reverse file" operation you perform just once a day.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Salem,
Logfile is viewed by user time to time through Excel(file is source for imported data into Excel).
To simplify things ,related to Excel, (i think) i need such 'at top' append.
It is possible to construct Excel sheet to use database (constructed on logfile) ,so last record will appear in top of screen. But this needs more complex work on Excel, and probably will need some tweaking/adjusting on end user computer. Which i want to skip.
regards
Clearly you don't know excel all that well, and are letting your fear of it get in the way of doing things sensibly.
If you overcome your fear and apply a little effort to learning excel, you would probably find it simpler to program excel to read the log file and display in reverse order (or display only the last few lines of the log file) rather than write your program to write new content at the beginning of a file.
Yes,grumpy,
i do not know Excel , i do not use it often than one time per 2 years.
My colleague consulted me about this case.
Anyway - logfile can be viewed with text viewer and on-top adding can be useful .
regards
Well if the first "field" of your log record is something like a date/time (that excel will recognise), then simply append the data to the file.
When you load it into excel, all you need do is then sort in reverse order, and you're done.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
A bunch of cars are waiting at a stop light. When a new car arrives, every single car goes into reverse and backs up to make room for the arriving car at the front of the line...
Sounds crazy, because it is.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Problem solved trough Excel->dataimport ->query... User opens 'book1.xls' , which imports logfile (.csv type - comma separated text). Sorting is stored and doesnt need user intervention. While constructing 'book1.xls' Excel asked for 'Microsoft query' to be installed. But final file contains all info needed, so ExcelViewer works allmost fine, without 'MS Query' installed. It seems .xls and .csv files can be delivered to end user as email.
Brewbuck, can You expand Your idea a little bit?
regards
Seriously?Brewbuck, can You expand Your idea a little bit?
He is saying that constantly rewriting a file to prepend data is foolish and prohibitively expensive when the alternatives are so efficient and readily available.
Soma
thanks,phantomotap - i missed irony.
on other hand - i dont agree with You - alternatives are not "so efficient and readily available". But it is question of taste.
regards
The only measure I can think of by which prepending input to the start of a file is efficient is that it avoids programming in excel to display the bottom of the file at the top of the screen.
In terms of where it is not so efficient, there are many possible measures.
The file writing the program is forced to rewrite the entire file whenever it writes a line, since no real-world operating system or disk file system supports prepending. Every time a line is written to the file, the existing contents of the file must be read and rewritten (or the file copied, which functionally achieves the same thing). So, if you are writing a line of 80 characters to a 1 KB file (which isn't all that big), prepending requires 1KB of data to be read from the file, the new line to be written, and the 1KB to be rewritten to the file. That means the program doing the prepending will write data to disk that is many, many, times the amount of data it is attempting to save. With the 80 char/1KB example, to write 80 characters the program must actually read 1024 characters from disk and write 1104 characters back. Compared with appending which will read 0 characters from disk and write 80 characters. That is a lot of additional I/O.
And what is one of the primary bottlenecks of real-world program performance? Disk I/O. Not because disk I/O is bad, but because it is often orders of magnitude slower than accesses of memory or execution of general (non-I/O) operations by the CPU.
Excel is pretty efficient at reading files (from top to bottom, anyway). Once excel has read the file, it is not typically necessary to read or write it again in order to show the last line read (other than a few exceptions such as swapping the program to disk on machines with very small amounts of physical memory).
So effectively you are proposing a scheme to slow down the program generating the data to a small fraction of the performance achievable by simply appending. For the negligible benefit of not having to tweak an excel spreadsheet/macro (once, ever, once you have learned how) and an almost insignificant runtime performance gain when running Excel.
Just because it may be to your taste does not mean your approach is particularly useful or valuable.
No. It really really really really really really really is not.But it is question of taste.
Wasting the clients bloody time because you don't understand the real world, which is almost exactly as grumpy described it*, is not a question of taste.
Soma
* It can actually be worse.