Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

strcmp problem

$
0
0
Hey all I am having a problem with this bit of code if someone would like to help!
The problem is it will crash when the last names are the same. Any help on this?

  bool LessThanByName( const Passenger & passenger ) const
   {
      char last0[MAX_LENGTH + 1];
      char last1[MAX_LENGTH + 1];
      char first0[MAX_LENGTH + 1];
      char first1[MAX_LENGTH + 1];
      
      for(int i = 0; i < last[i]; i++)
      {
         last0[i] = last[i];
     }   
      for(int i = 0; i < passenger.last[i]; i++)
      { 
        last1[i] = passenger.last[i];
      }
      for(int i = 0; i < first[i]; i++)
      {   
         first0[i] = first[i];
      }
      for(int i = 0; i < passenger.first[i]; i++)
      {   
         first1[i] = passenger.first[i];
      }
      
      if(strcmp(last0, last1) == 0)
        {
         return (strcmp(first0, first1) < 0);
        }
      return (strcmp(last0, last1) < 0);
   }

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>