CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Array of Structures Problem

  1. #1
    Join Date
    Feb 2010
    Posts
    19

    Array of Structures Problem

    Code:
    for (loop = 0; loop < (seqread - 1); loop++) {
    	if (name == Datalist[loop].Name) {
    		difsearch1 = loop;
    	}
    }
    Out << difsearch1 << endl;
    I'm having some problems getting this code to work right. Actually I'm not sure it will ever work right I just posted it as an example to show you what I need to do. I read in the 'name' string from an input file and I have Datalist[n] full of 3 types from a separate input file. The problem is that I am 100% positive that the exact same string variable 'name' is stored at some 'n' in Datalist. All I need to do is to get that int ' n' where 'name' is stored in Datalist. This is the only way I could think of how to do it and it doesn't work because for some reason that 'if' statement is never true. If anyone has any suggestions on an alternative way I could go about doing this I would really appreciate the help. Thanks.

  2. #2
    Join Date
    Aug 2008
    Posts
    902

    Re: Array of Structures Problem

    Post all of the code, not just a tiny little morsel of code, which has no meaning on it's own. We have no context to go on.

  3. #3
    Join Date
    Feb 2010
    Posts
    19

    Re: Array of Structures Problem

    Code:
    	while (In) {
    
    		getline(In, name, '\t');
    		getline(In, species, '\t');
    		getline(In, sequence);
    
    		seqread++;
    	}
    
    	In.clear();
    	In.close();
    	In.open("sequences.txt");
    
    	const int MAXLINES = 25;
    	Protein Datalist[MAXLINES];
    
    	for (numLoops = 0; numLoops < (seqread - 1); numLoops++) {
    		getline(In, name, '\t');
    		getline(In, species, '\t');
    		getline(In, sequence);
    
    		sequence = RLEdecode(sequence);
    
    		data.Name = name;
    		data.Species = species;
    		data.Sequence = sequence;	
    
    		Datalist[numLoops] = data;
    	}
    
    	while (In2) {
    		getline(In2, command);
    		
    		commandsread++;
    	}
    
    	In2.clear();
    	In2.close();
    	In2.open("commands.txt");
    
    
    	for (numLoops = 0; numLoops < (commandsread - 1); numLoops++) {
    		In2 >> command;
    		
    		if (command == "search")
    		{
    			Out << "00" << (numLoops + 1) << "   search    ";
    			getline(In2, sequence);
    			RLE = RLEdecode(sequence);
    			num = search(RLE, Datalist, seqread);
    			Out << RLE << "  " << endl << "organism                      protein" << endl;
    			if (num != (seqread - 1))
    				Out << Datalist[num].Species << "      " << Datalist[num].Name << endl;
    			else Out << "NOT FOUND" << endl;
    			
    		}
    
    		if (command == "diff")
    		{
    			Out << "00" << (numLoops + 1) << "   diff   ";
    			getline(In2, name, '\t');
    			getline(In2, name2);
    		    Out << name << "   " << name2 << endl << "amino acids difference" << endl;
    			dif = difference(Datalist);
    			Out << dif << endl;
    		}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)