Loop problem

1
2
3
4
5
6
for (loop = 0; loop < (seqread - 1); loop++) {
	if (name == Datalist[loop].Name) {
		difsearch1 = loop;
	}
}
Out << difsearch1 << endl;


How come when I try to output "difsearch1" I get a crazy long negative number? Lets say for example that "name == Datalist[3].Name", I want difsearch1 to equal 3 as well. It's probably something simple that I've done wrong but I don't see why that code won't work. "seqread" equals 6 in this case, by the way. Thanks for the help.
Last edited on
post some more code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (command == "diff")
{
	Out << "00" << (numLoops + 1) << "   diff   ";
	getline(In2, name, '\t');
	getline(In2, name2);
        Out << name << "   " << name2 << endl << "amino acids difference" << endl;
			
	for (loop = 0; loop < (seqread - 1); loop++) {
		if (name == Datalist[loop].Name) {
			difsearch1 = 5;
		}
	}
	Out << difsearch1 << endl;
  }
The obvious answer is that no match was found.

If your code is not too long can you post it all?
You are right... as you can see I used getline() to get name. I got the variable "name" from one input file and Datalist[n].Name stores the exact same name I'm 100% positive but it came from another input file. Could that be the reason that no match was found? I did a simple comparison to see if "name == Data[0].Name" was true and it wasn't. But I know for a fact that location stores the same thing that's in name. I have that name stored in the struct Datalist and all I need is the location of where it's at. All I need is the number inside the brackets of where that name is stored in my struct.
Last edited on
Topic archived. No new replies allowed.