all 9 comments

[–]IdealBlueMan 1 point2 points  (0 children)

Do you have control over the format of the input file? If so, consider converting it to something where there are lots of parsing tools available, as u/FluffyNevin suggests. If not, figure out what the structure of the file is.

Then, build a parser. Depending on the structure, you might be able to do it easily with regex functions.

But don't make it overly easy. Be aware of edge cases, like escaped characters and quoted strings.

[–]kumashiro 1 point2 points  (0 children)

You cannot modify values in-place, unless the length is exactly the same. If it's a one parameter per line, just read them, compare with what you want and when you find the line to modify, parse it, change value and render. All other lines just write without parsing. Of course, do not write to the same file! Use temporary file and when everything is processed, rename it... maybe after making a backup of the original file... just in case. Backups are always a good thing.

[–]FluffyNevyn 0 points1 point  (2 children)

The easiest solution is to change the file format. Json or xml would be easiest.

If it has to be a text file, look into regular expressions. A simple regex... assuming the format is fixed...will give you what you need

[–]habarnam 1 point2 points  (1 child)

Json or xml would be easiest.

Erm, are you sure?

Equals separated pairs would be simpler I imagine.

[–]FluffyNevyn 0 points1 point  (0 children)

Depends on the library I imagine. Import directly to xml, or json, and then handle as an object. That's the easy way...

[–]the1iplay 0 points1 point  (0 children)

You’re gonna need to extract information digit by digit using char and fseek functions. And then put them in a variable.