Thread: strcomp of 3 strings

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    how find that with two comparisons

    ??

  2. #17
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    edit

  3. #18
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    like this?
    Code:
    if(strcmp(f1,f2)>0)
    	 {
                if (strcmp(f2,f3)>0)
                  smallest is f3 
    	 }
    	 else
    	 {
                if (strcmp(f1,f3)>0)
                  smallest is f3
    	 }

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    Yes, you are getting closer, but you are not there yet. Think about the cases where f1 and f2 are the smallest.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    but still in the inner if i could get <0
    so there i need to add another else
    which is the same if

  6. #21
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    Code:
    if(strcmp(f1,f2)>0)
    	 {
           if(strcmp(f2,f3)>0)
    	   {
              return f3;
    	   }
    	   else
    	   {
    		   return f2
    	   }
    	 }
    	 else
    	 {
           if(strcmp(f1,f3)>0)
    	   {
              return f3;
    	   }
    	   else
    	   {
    		   return f1
    	   }
    	 }
    like this?

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    Yes, but don't just take my word for it: test it yourself.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Problems with strings as key in STL maps
    By all_names_taken in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:34 AM
  4. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM