11
I came across the following questions:
- What is the difference between expressions
strcpy (s, t) e s = t
? - What is the difference between 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 your behavior that is not similar to command strcmp
. What does it mean then if(s<t)
? Since s and t are vectors of char
(strings)?
The codes that follow were in the same questions from which to extract the questions quoted at the beginning and I am posting them because they serve as an "illustration" of the question.
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);
Someone who understands of C could improve the title of this question? This way it is not clear the doubt, but the question seems interesting.
– Molx