Hello, I haven't done any work with reading or writing from/to files in C++, I think we did some C in school but its all a little fuzzy at this point.

What I need to do is store the values for a couple different functions in a text file, have the function find its section and set the variables accordingly. Having a different text file for each function would probably be the easiest way but having one text file would easier when anyone else goes to use the program.

For example, some pseudo code, if I had this:

void setSOT(text file){
searches for SOT section, sets variables
}

And if this were my text file

SOT

bit 1 = 1
bit 2 = 0
.
.
.
bit 7 = 1

EOR

bit 1 = 1

.
.
.

etc

How would I go about only parsing that one section of the text file that pertains to the SOT function. Or if you could simply point me to a relevant tutorial :D I've been searching but have yet to find one.

Thanks

Recommended Answers

All 2 Replies

A more concise idea of what I'd like to accomplish

some more pseudo code

open file
if(line = 'keyword'){
while(line != #){
if value is an integer place it in array
}
}

where the keyword would be different depending on the function

The psudocode just confuses me. Perhaps post the "before" and "after" of the file and what's changing? Is this something like you're "setting" bit 2 of the SOT portion of the file to 1? you need to traverse the file, find "SOT", then find the "bit 2", then find the equals sign in that line, then set what's after the equals sign to "1"?

Before

SOT

bit 1 = 1
bit 2 = 0
.
.
.
bit 7 = 1

EOR

bit 1 = 1

.
.
.

etc

After

SOT

bit 1 = 1
bit 2 = 1
.
.
.
bit 7 = 1

EOR

bit 1 = 1

.
.
.

etc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.