Showing posts with label char*. Show all posts
Showing posts with label char*. Show all posts

17.9.15

How to find the smallest string in C++

Write a function  min that has three C string parameters and returns the smallest.

Solution
char* min(char* a, char* b, char* c)
{
    return strcmp(a,b) < 0 ? strcmp(a,c) < 0 ? a : c : strcmp(b,c) < 0 ? b : c;
}