-3

I am having difficulty getting the real output from a C function. For example:

int max3(int a, int b, int c){
    if ((a>b)&&(a>c))
       return a;
    if ((b>c)&&(b>a))
       return b;
    return c;       
}

Can you give me an idea of how to specify the real output (e.g. tools, algorithms, etc.)? In this above example, the real output is 6 (in case (a,b,c) = (1,2,6)). Thank in advance very much.

Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46
ducanhnguyen
  • 161
  • 1
  • 10
  • 6
    Quite unclear what you call the "real" output. Please explain. –  May 19 '14 at 15:25
  • Isn't it working as intended (i.e. 6 is returned)? – Fiddling Bits May 19 '14 at 15:36
  • 1
    If you want to know what the method outputs, **run it and then you'll know**. – Eric Lippert May 19 '14 at 15:58
  • @YvesDaoust : my tool accepts input (CUnit )written in C; and the tool is written in Java. To be specific, i have to find a way to analyse the CUnit so obtain the return value from a function in java environment. – ducanhnguyen May 20 '14 at 01:40
  • Do you mean that you cannot retrieve from the error report the value actually computed by the function ? If true, a solution is to define your own `CU_ASSERT` macro in such a way that it not only checks the returned value, but also formats (`sprintf`) the value in a string buffer, then passes it to `CU_assertImplementation`. –  May 20 '14 at 07:11

1 Answers1

1

I'd have probably written it, as it is simple, using the ternary operator:

int max3(int a, int b, int c){       
    if (a>b)
       return (a>c)?a:c;
    else 
       return (b>c)?b:c;
}
JohnH
  • 2,713
  • 12
  • 21