Help with Strings in C
Posted
by Anon
on Stack Overflow
See other posts from Stack Overflow
or by Anon
Published on 2010-04-21T03:51:19Z
Indexed on
2010/04/21
3:53 UTC
Read the original article
Hit count: 386
c
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).
I've tried and came up with this:
if ((strcmp(name1,name2)>0)&&(strcmp(name1,name3)>0)){
max=name1;
}
else if ((strcmp(name2,name1)>0)&&(strcmp(name2,name3)>0)){
max=name2;
}
else if ((strcmp(name3,name1)>0)&&(strcmp(name3,name2)>0)){
max=name3;
}
However, I get this error Your code is incorrect. You are not handling the situation where two or more strings are equal.
© Stack Overflow or respective owner