How to replace NaN values in text file?

Pages: 12
Hello nicholasjb1996,

As your program is growing I agree with FurryGuy that a struct is a good idea unless you want to build a class.

Right now you are more familiar with how the information is stored in the file. When I tried to break up the first two lines this is the way I see it:

************* Line 1 ****************
1 1383266NaN0000 39

1        grid
1383266  ?
0        ?
0000     ?
39       country code

************* Line 2 ****************
1 1383267000000 0 0.02730046487718618

1                    grid
1383267000000        ?
0                    country code?
0.02730046487718618  ?

Not sure if I am understanding this right or if it needs broken down more or differently? To me line 2 is missing a proper country code because I do not believe that zero is correct.

Line 2 is short and ends with a large decimal number that I am not sure what it is for or how to deal with it.

Once I better understand what the numbers mean I can set up a struct to put the information in.

Hope that helps,

Andy
When I put the information in here to post it gets messed up because of how long one line is.
1
2
3
4
5
6
7
1	1383262200000	39	0.68143NaN796890551	0.22081529861558874	0.02730046487718618	0.05343788914147278	8.622424590989748
1	1383262800000	0	0.02730046487718618
1	1383262800000	39	0.24337810266887647	0.1928905642458027	0.05343788914147278	0.08073835NaN1865896	8.009927462445756
1	1383263NaN0000	0	0.02730046487718618
1	1383263NaN0000	39	0.0563882398598718	0.24337810266887647	0.02730046487718618	0.02730046487718618	8.11841955NaN896
1	138326NaN00000	0	0.029712044475285478			0.003574620210998875
1	138326NaN00000	39	0.13533928377303134	0.0849372437222577	0.05343788914147278	0.0017873101054994376	8.026269748512151

This is how the data looks in the file.
The following is in order of columns:
Square ID(GRID ID), Time Interval, Country Code, SMS In Activity, SMS Out Activity, Call In Activity, Call Out Activity, Internet Traffic Activity. As you can see in the above, the sample I posted from the file has one long decimal value out of column alignment and in the text file there are a lot of them that are out of alignment with their respective columns. I want to align them into their respective columns and if perhaps have each column in their own (array or vector)? There is a total of 512 rows and 8 columns. I tried to create a function to fix the data but this is what I came up with and wasn't working.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
int clean(int *num)
{
	*num = 512;

	fstream clean("cis.xlsx");
	if (clean.is_open())
	{
		int c = 0;

		clean >> si[c] >> ti[c] >> cc[c] >> smsi[c] >> smso[c] >> ci[c] >> co[c] >> ita[c];

		if (smsi == NULL)
		{
			smsi[c] = 0;
		}

		if (smso == NULL)
		{
			smso[c] = 0;
		}

		if (ci == NULL)
		{
			ci[c] == 0;
		}

		if (co == NULL)
		{
			co[c] = 0;
		}

		if (ita == NULL)
		{
			ita[c] = 0;
		}

		cout << si[c] << " " << ti[c] << " " << cc[c] << " " << smsi[c] << " " << smso[c] << " " << ci[c] << " " << co[c] << " " << ita[c] << endl;
		c++;
	}
}

I know the return type is supposed to be of type int but I have no idea what to return.
All variables declared outside the function.
si=Sqaure ID
ti=Time Interval
cc=Country Code
smsi=SMS In
smso=SMS Out
ci=Call In
co=Call Out
ita=Internet Traffic Activity
Last edited on
Topic archived. No new replies allowed.
Pages: 12