Hi guys:

The following code compares two folders and if the input is correct will print out the data. That's not my problem, I wanted to add an empty line when the comparison is incorrect. The things is that it adds a good amount of empty lines before I get the input. I tried a do while loop or two if statements and they gave me the same output. How can I get this to work ? Thank you,

Gus

Code

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
	char cmpFile[20];
	int numberRaw=486;
	int numberImages = 100;

	ifstream in,in2;
	in.open("atos.comp");
	in2.open("go.comp");
	ofstream out("stdmag.comp");

	
	double ierr,serr,verr,isn,iln,vn,x,y,sharp;
	vector<double> bestId(numberImages);
	vector<double> idil(numberImages);
	vector<double> idis(numberImages);
	vector<double> idv(numberImages);
	vector<double> idile(numberImages);
	vector<double> idise(numberImages);
	vector<double> idve(numberImages);
	vector<double> stardId(numberRaw);
	for (int i=0; i<numberRaw; i++) 
	{
		in2 >>stardId[i];
		for(int j=0;j<numberImages;j++)
			{
				in >>bestId[j]>>idil[j]>>idile[j]>>idv[j]>>idve[j];
				if (stardId[i]==bestId[j])
					   {
						   out <<"  "<<idil[j]<<"   "<<idile[j]<<"  "<<idv[j]<<"   "<<idve[j]<<" "<<bestId[j]<<endl;
					   }
/*				if (stardId[i]!=bestId[j])
				{
					out <<endl;
				}*/
					   
			}
		
	}
	out << endl;
	return 0;
}

atos file (not entire file since the file is 24000+ lines)

9	12.417	0.005	10.109	0.005
15	12.786	0.005	10.500	0.005
16	12.322	0.005	10.887	0.005
19	12.481	0.005	11.096	0.005
26	13.035	0.006	11.215	0.006
29	13.823	0.005	10.926	0.005
40	14.187	0.005	11.132	0.005
44	14.521	0.006	11.160	0.006
65	13.639	0.005	12.083	0.005
66	14.244	0.008	11.844	0.008
69	13.671	0.006	12.148	0.005
75	14.447	0.005	11.899	0.005
79	13.918	0.006	12.201	0.005
88	14.219	0.005	12.194	0.005
95	14.208	0.005	12.314	0.005

go.comp file(same as atos file)

2
29
149
168
139
230
40
9
4
203
302
265
245
242
264
240
243
233
251

Can you be more specific about when you want an blank line? Because as I see it, doing it at the same place as the stardId[i]==bestId[j] comparison will most certainly result in a lot of blank lines unless the two files correspond in the ID field.

The idea is that the code will compare starID and BestID. If starID and BestID are equal give the output in that line from the atos.comp file. If they are not equal then add a blank line and compare the next.
So if for example I have for the atos.comp file this

9	12.417	0.005	10.109	0.005
15	12.786	0.005	10.500	0.005
16	12.322	0.005	10.887	0.005
19	12.481	0.005	11.096	0.005

and the go.comp file has this

2
15
16
168
19

I will expect the following output

[I]Empty line[/I]
15	12.786	0.005	10.500	0.005
16	12.322	0.005	10.887	0.005
[I]Empty line[/I]
19	12.481	0.005	11.096	0.005

Does it make sense ?

Okay, in your example there are two cases:

  1. For 2 and 9, print a blank line and read a new ID from both files
  2. For 168 and 19, print a blank line and only read a new ID from go.comp such that the two 19 lines match

How do you tell between those two cases when constructing the desired output?

Set up a flag (OuputBlank) initialized to TRUE.
When you output a blank line, set flag to FALSE.
Next time you need to output a blank line, test the flag first.
When you output a non-blank line, set the flag to TRUE.

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.