I would like to extract and analyse the data but the data behind the NUL entry is not accessible for me maybe due to the fact that NUL normally marks the end of a line. Is there a method to remove the NUL entries in this text file?
I presume you wrote the code that generated the txt file? As such I would suggest you check for the condition that generated the NUL entries and don't allow it to write anything to txt file.
If you cannot change the code, it does look like the record size is fixed. So you might be able to open the file as binary and then read fixed size blocks in using ifstream::read()
I presume you wrote the code that generated the txt file? As such I would suggest you check for the condition that generated the NUL entries and don't allow it to write anything to txt file.
Unfortunalely I do not have access to the code that generated the txt file and I already have hundreds of files formatted this way.
I will try to open the file as binary as Andy suggested.
If you have another ideas, please post them.
Is there a method to remove the NUL entries in this text file?
You could write a small utility program that just opens each file, reads each line and parses the fields delimited by the semi-colon and effectively filter out the NUL; fields. Then just output to a new file.
You could write a small utility program that just opens each file, reads each line and parses the fields delimited by the semi-colon and effectively filter out the NUL; fields. Then just output to a new file.
That's what I tried but if I use the following command
file.getline(row, 1024);
the variable "row" only contains the string "DS2007;50000007;" and nothing else.
Opening the file in binary mode does not yield better results.
I am not very experienced in working with text files so I don't really know how to proceed.
Unfortunately I have 80 of the measuring boards I mentioned above. The software has a small bug in writing this column containing "Nul" values.
This code works with char buffers and uses istream::gcount to find out how many chars were read by the last operation (inc. term null, hence the -1 adjustment.)
If you use std::replace with std::string you don't have to worry about gcount, you just use begin() and end() as usual.
your solutions both work very well!
Thanks a lot all of you for your help.
This saves a lot of time for me as I will not have to manually format several hundred text files.