10.4: Library Functions for Working with C-Strings: 10714

Question

Write a function  max that has two C string parameters and returns the larger of the two.

Solution
char* max(char *a, char *b)
{
    int result = strcmp(a, b);

    if (result > 0)
        return a;
    else
        return b;
}

1 comment:

  1. char* max(char *a, char *b)
    {
    if(strcmp(a, b)>0)
    return a;
    else
    return b;
    }

    ReplyDelete