Pointer issue when looking through .txt

This is a discussion on Pointer issue when looking through .txt within the C++ Programming forums, part of the General Programming Boards category; Okay so here is what i have. It is suppose to search both male names and female names. But if ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    28

    Pointer issue when looking through .txt

    Okay so here is what i have. It is suppose to search both male names and female names. But if it finds one it displays that one and not the other (Some names work for boys and girls). What should i do to make it re' search through the list and find the other names. Thanks.

    Code:
    	while (!terminate)
    	{
    		cout << "Enter a name (First letter must be a Capital) or type 'done' to finsh searching.\nName: ";
    		string target;
    		cin  >> target;
    		
    		tempPtr = topList;
    
    		while ((tempPtr->boysName != target) && (tempPtr->link != NULL))
    		{
    			tempPtr = tempPtr->link;
    		}
    		
    		// If done is typed a user is finished and program terminates.
    		if (target == "done")
    			terminate = true;
    			
    		
    		else if (tempPtr->boysName == target)
    		{
    			cout << target << " is ranked " << tempPtr->rank << " among boys' names.\n" << endl;
            }
            
    		else
    			cout << "Name not found in Babynames2004 database" << endl;
    			
    			
    			
    		while ((tempPtr->girlsName != target) && (tempPtr->link != NULL))
    		{
    			tempPtr = tempPtr->link;
    		}
    		
    		// If done is typed a user is finished and program terminates.
    		if (target == "done")
    			terminate = true;
    			
        	else if (tempPtr->girlsName == target)
        	{
                 
    			cout << target << " is ranked " << tempPtr->rank << " among girls' names.\n" << endl;
            }
    		else
    			cout << "Name not found in Babynames2004 database\n" << endl;
    			
    	}
    EDIT: i fixed it all i had to do was have it repoint to the top of the list, stupid me!
    Last edited by kordric; 05-15-2008 at 05:00 PM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Cleaned up the thread a bit.
    Last edited by VirtualAce; 05-17-2008 at 11:46 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. sorting with pointer of pointers to array
    By dunpealslyr in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2007, 11:26 PM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  4. Pointer validity check
    By Carlos in forum Windows Programming
    Replies: 6
    Last Post: 12-11-2003, 02:40 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21