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

Question

Given the  char * variables  name1 ,  name2 , and  name3 , write a fragment of code that assigns the largest value to the variable  max (assume all three have already been declared and have been assigned values).

Solution
max=name1;
if (strcmp(name2, max)>0)
    max=name2;

if (strcmp(name3,max)>0)
    max=name3;

No comments:

Post a Comment