I came across the following questions:
- What is the difference between the expressions
strcpy (s, t) e s = t
? - What is the difference between the expressions
if (strcmp (s, t) < 0) e if (s < t)
?
I tried to compile the code s=t
of the first question, but I got an error. However I can compile if (s<t)
, but I noticed by its behavior that it is not similar to the strcmp
command. What does if(s<t)
mean? Since s and t are vectors of char
( strings )?
The codes that follow were on the same questions from which to extract the quoted questions at the beginning and I'm posting them because they serve as an "illustration" of the question. Home What's wrong with the code segment below?
char b[8], a[8];
strcpy (a, "abacate");
strcpy (b, "banana");
if (a < b)
printf ("%s vem antes de %s no dicionário", a, b);
else
printf ("%s vem depois de %s no dicionário", a, b);
char *b, *a;
a = "abacate";
b = "banana";
if (a < b)
printf ("%s vem antes de %s no dicionário", a, b);
else
printf ("%s vem depois de %s no dicionário", a, b);
char *a, *b;
a = "abacate";
b = "amora";
if (*a < *b)
printf ("%s vem antes de %s no dicionário", a, b);
else
printf ("%s vem depois de %s no dicionário", a, b);