Problem searching an array with String Compare

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dave2020
    New Member
    • May 2007
    • 2

    Problem searching an array with String Compare

    Im new to C++ and having a bit of a problem,

    I have a program, written in Visual C++, designed to take in data and then let a user search through it but while it lets the user search it never comes back with my error message if the search isnt successful

    Code:
    {
    	char search_town[16];
    	int result = 0;
    	int sub = 0;
    	bool custfound = false;
    	
    	gotoxy (22,13);
    	Input (search_town,15);
    
    	do
    	{
    		result = (_strnicmp(search_town,record[sub].town,strlen(search_town)));
    		if (result == 0)
    		{
    			DisplayCustomer(record[sub]);
    			custfound = true;
    		}
    		sub ++;
    	}
    	while (sub < count);
    
    	if (custfound = false)
    	{	
    		Error("*No record matching that search found*");
    		PressKey();
    		SearchDetails(record, count);
    	}
    }
    when executed, if an invalid search is entered it just skips past the error message and straight into the next function but valid searches are fine, any suggestions as to why would be really appreciated
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by Dave2020
    Im new to C++ and having a bit of a problem,

    I have a program, written in Visual C++, designed to take in data and then let a user search through it but while it lets the user search it never comes back with my error message if the search isnt successful

    Code:
    {
    	char search_town[16];
    	int result = 0;
    	int sub = 0;
    	bool custfound = false;
    	
    	gotoxy (22,13);
    	Input (search_town,15);
    
    	do
    	{
    		result = (_strnicmp(search_town,record[sub].town,strlen(search_town)));
    		if (result == 0)
    		{
    			DisplayCustomer(record[sub]);
    			custfound = true;
    		}
    		sub ++;
    	}
    	while (sub < count);
    
    	if (custfound = false)
    	{	
    		Error("*No record matching that search found*");
    		PressKey();
    		SearchDetails(record, count);
    	}
    }
    when executed, if an invalid search is entered it just skips past the error message and straight into the next function but valid searches are fine, any suggestions as to why would be really appreciated
    What is the Error function supposed to do? Also, shouldn't your last part say:
    Code:
    if (custfound [B]==[/B] false)   //2 equal signs
    	{	
    		Error("*No record matching that search found*");
    		PressKey();
    		SearchDetails(record, count);
    	}

    Comment

    • Dave2020
      New Member
      • May 2007
      • 2

      #3
      doh! now I feel a bit stupid, didnt notice I'd only put the one = in there....change d it and it works now, thanks a million, that's been driving me nuts for hours.

      As for the error function, it displays a message at the bottom of the screen, waits for the user to press enter and then lets them enter the value again

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by Dave2020
        doh! now I feel a bit stupid, didnt notice I'd only put the one = in there....change d it and it works now, thanks a million, that's been driving me nuts for hours.

        As for the error function, it displays a message at the bottom of the screen, waits for the user to press enter and then lets them enter the value again
        No problem

        Comment

        Working...