Infection Simulator reading file problem cpp

Status
Not open for further replies.

turuk

Junior Member level 3
Joined
Aug 30, 2019
Messages
29
Helped
0
Reputation
0
Reaction score
1
Trophy points
1
Activity points
224
I have to create an environment including infected and healthy entities. Im stuck at finding an efficient way to get the input data. Data that i need are: size, number of turns, positions in each turn, entities properties(gates, being infected or healthy, starting position). I want to extract only them. It would be great if you give any ideas.

Here is an example input:

 

Create arrays:

entity(x)

data_string(x)

Whether_infected(x)

Where x = 1 to amount of entities.

At the beginning set Whether_infected to 0 for all entities.

As soon as you determine an entity is infected, print data_string for that entity.

Or, set Whether_infected to 1 (or -1, or 9, or -9, etc.). At the end of the run, print data_string if Whether_infected is non-zero.
 

I want to extract the values. I found that seekg() function can help but i couldnt make it work in long inputs.
 

Perhaps you mean you want to parse long strings of alphanumerics? Then you must examine each character in sequence. Begin each datum as a null string.

Build each datum by appending digits. When you find a space or 'x' then it marks the end of a datum.

'Infected' appears in your log a few times. So I guess the first thing is to search each string for that word. If it's found then go through the parsing steps.

- - - Updated - - -

In BASIC you convert a string of characters into a number by using the VAL command.
 

can you write an example code about what you said?
 

The code does a similar job as a 'robust' input routine. The purpose is to accept user keypresses, then convert ascii characters into proper data consisting of words and numbers.
You must ensure that your routine misses no piece of data, and furthermore it cannot be made to crash by any unexpected keypress (accidental or deliberate).

Obviously you need to tailor the routines to handle your particular needs. I guess you use a different programming language than BASIC.

As an example...
To examine one or more characters within a string, BASIC has these command keywords:
MID$(a$,x,y)
MID$(a$,b$)
LEFT$(a$,x)
RIGHT$(a$,x)
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…