With strcmp. The result would be less or greater than zero.
#include <stdio.h>
#include <string.h>
int main(void)
{
static const char a[] = "12345620", b[] = "123456708";
int result = strcmp(a, b);
printf("%s %s %s\n", a, result < 0 ? "<" : result > 0 ? ">" : "=", b);
return 0;
}
/* my output
12345620 < 123456708
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
>But, how do you see if one string is less than the other?
strcmp returns one of three values: 0 if the strings are of equal length and content, a value less than 0 if the first string is shorter or smaller in value than the second string, and a value greater than 0 if the first string is longer or larger in value than the second string.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
you can try using the standard library function in string.h.
use the strlen() function.here is how you do it.:
1.declare two variables say i,j for your two strings say str1,str2
2.let i=strlen(str1);j=strlen(str2);
3.if(i>j) str1 is larger string
else str2 is the larger string.
hope this is helpful.
indianscorpion2
Junior Poster in Training
82 posts since May 2005
Reputation Points: 9
Solved Threads: 1