Programming for software intermingling(?)

Started by
34 comments, last by lb2024 9 years, 10 months ago


And what is the best method of reading .dat files and having my code understand which portions to change if wrong and which ones to record?

That requires you to know the format of the file. The '.dat' file extension is just a generic notation for files containing data - there isn't any implied structure to the data.

To do anything useful with the data, you have to know how it is formatted. Either by reading a format specification provided by the author of the software which created that file, or by opening up the file in a text/hex editor, and reverse-engineering the structure.

If you open up the file in Notepad and you find you can read the contents easily, then it is a plain-text format, and will be fairly easy to interpret. If you open it in Notepad and it is just gibberish, then it is a binary format, and reverse engineering will be a painstaking process conducted with a hex editor, and healthy supply of caffeinated beverages.

If you are able to upload a sample of such a file, one of us can take a look and tell you if this is feasible.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Advertisement

Thanks so much guys!!! It's easily read through notepad, so I'm getting the feeling this won't be too hard. So, since I know it's plain-text format, what do I need to do next? I assume what I'm reading are variables but I need to know how to check the values since they will change depending on the file. Here is what it reads like in the notepad:

**Note if I'm doing anything wrong looking at this file through a Hex editor or posting this let me know. I don't want to be doing anything illegal or unethical. I'm just trying to create something to read these and determine if it is good or needs to be changed.

*edit deleted code. (nothing was too important)



Ok, yes, that data format is dead simple. Basically an INI file, with the additional of tab-delimited columns.

You may well find there is an off-the-shelf INI parsing library that would load this, but if not, you want to follow the basic steps:

- open the file, read it a line at a time:

+ if the first character is a '#', ignore the line

+ if the first character is an '<', treat it as a section header

+ if the line contains a '=', assume everything up to the '=' is the key name, everything after is values separated by tabs

Probably simple enough you can get away with using a C-style scanf() to parse the actual values.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

But to recheck before I cry triumph, let me gather if I got my logic down right.

For me to check a folder and it's content, I will need to learn about "api's" (ie. I have a folder with data and a txt file in which shows what should be in the folder I use some type of reader to crosscheck txt file and filenames in folder)

For me to check the values of the contents of my data file, I load the data file into possibly scanf() and search for specific strings and record my values. I then will print out the values in a txt format for use later.

I still haven't figured out how to input it into excel automatically, but I'm assuming the "api's" will have something to do with it.

Am I on the right track?

Sort of. In brief:

- Reading files is built into the C++ standard library. Go learn about file streams.

- Parsing values from text can be accomplished in many ways, you'll probably either want to use file streams directly or the scanf() functions.

- Directory manipulation is not built into C++, so you might look at the aforementioned boost::filesystem.

- Modifying Excel files is not built in either, but there are 3rd-party libraries to help you out.

That said, I don't at this point have a good feel for your experience programming in C++, so a bunch of that may require significant other reading before you tackle it.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Im intermediate. Might be a small curve but I feel confident in a month I could figure it out. Plus you guys been so helpful once I start coding I'll ask for help if I get stuck somewhere. Thanks for the help for real.

This topic is closed to new replies.

Advertisement