Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Infection Simulator reading file problem cpp

turuk

Junior Member level 2
Joined
Aug 30, 2019
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
155
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:

size 13
turn_count 68
entity 1 DDCBD 11x1 infected
entity 2 GBEAC 12x13
entity 3 FFDGH 1x10
entity 4 DCBEG 5x12
entity 5 DCDBH 8x3 infected
entity 6 BBEFD 1x3
entity 7 HACHE 11x3
entity 8 ADGBD 11x4
entity 9 BDAHA 2x2
entity 10 CEBDF 7x1
entity 11 CAHDD 9x8 infected
entity 12 ADFBD 10x7
entity 13 DFACG 7x5
turn 1 8x3 5x1 11x7 6x12 11x6 3x11 1x4 5x6 5x8 3x13 13x9 6x13 4x9
turn 2 10x10 3x4 6x12 7x12 9x1 11x9 3x9 1x3 12x11 1x2 3x6 8x6 5x2
turn 3 12x2 7x2 13x4 9x1 3x9 1x3 3x7 13x1 13x3 7x13 4x9 2x10 4x12
turn 4 2x2 2x6 4x5 7x12 8x4 10x5 11x4 6x11 2x12 11x5 4x13 10x4 1x11
turn 5 1x3 6x10 11x5 10x10 6x1 9x7 2x10 8x10 8x3 2x1 11x9 13x7 6x6
turn 6 5x13 5x11 5x1 8x10 2x12 7x9 6x11 6x12 13x4 2x8 12x5 10x11 1x6
turn 7 10x13 4x8 2x9 3x4 5x10 12x9 13x8 6x4 5x8 12x7 10x6 13x5 4x11
turn 8 4x12 2x2 11x3 1x3 12x11 10x7 3x6 4x9 9x7 4x7 2x12 6x10 8x8
turn 9 12x4 4x5 5x11 2x3 10x4 9x5 11x1 8x1 2x12 10x8 7x2 11x4 6x13
turn 10 12x2 7x4 1x1 10x7 8x7 13x3 3x10 12x1 6x9 7x12 5x8 13x4 2x2
turn 11 1x5 9x7 2x8 3x12 10x2 7x2 9x13 8x1 12x2 5x6 12x1 12x12 7x6
turn 12 9x11 3x5 2x11 8x8 3x9 5x12 13x3 2x4 8x10 11x4 5x2 12x3 4x12
turn 13 4x6 1x1 5x2 3x10 6x7 11x5 2x1 11x6 2x10 7x3 6x3 9x4 8x4
turn 14 1x9 13x8 7x4 6x12 12x3 3x12 2x8 10x4 7x7 7x9 7x6 3x5 11x2
turn 15 6x13 10x7 13x12 9x1 1x7 10x2 13x3 1x5 9x5 11x6 7x5 10x3 8x7
 

BradtheRad

Super Moderator
Staff member
Joined
Apr 1, 2011
Messages
13,476
Helped
2,667
Reputation
5,330
Reaction score
2,575
Trophy points
1,393
Location
Minneapolis, Minnesota, USA
Activity points
100,764
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.
 

turuk

Junior Member level 2
Joined
Aug 30, 2019
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
155
I want to extract the values. I found that seekg() function can help but i couldnt make it work in long inputs.
 

BradtheRad

Super Moderator
Staff member
Joined
Apr 1, 2011
Messages
13,476
Helped
2,667
Reputation
5,330
Reaction score
2,575
Trophy points
1,393
Location
Minneapolis, Minnesota, USA
Activity points
100,764
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.
 

turuk

Junior Member level 2
Joined
Aug 30, 2019
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
155
can you write an example code about what you said?
 

BradtheRad

Super Moderator
Staff member
Joined
Apr 1, 2011
Messages
13,476
Helped
2,667
Reputation
5,330
Reaction score
2,575
Trophy points
1,393
Location
Minneapolis, Minnesota, USA
Activity points
100,764
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)
 

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top