My function needs to lexicographically calculate the value of the characters (by the ASCII table) of the string. For example:
"Alibaba" and "Came"
'A' = 65 and 'V' = 86
65 - 86 = -21.
Then the function would return l1
and if it were equal the first would go to the next letter. If all letters are equal, it would return 0. But it is always returning l2
. Am I doing the wrong calculation?
My code:
void str_comparacao(char str1[], char str2[])
{
int i=0;
int y;
while(str1[i] != 'void str_comparacao(char str1[], char str2[])
{
int i=0;
int y;
while(str1[i] != '%pre%' && str2[i] != '%pre%')
{
while(str1[i] != str2[i])
{
if(str1[i]==str2[i])
{
y=str1[i]-str2[i];
}
i++;
}
i++;
}
if(y<0)
printf("L1, str1 < str2\n");
else
printf("L2, str1 > str2\n");
}
' && str2[i] != '%pre%')
{
while(str1[i] != str2[i])
{
if(str1[i]==str2[i])
{
y=str1[i]-str2[i];
}
i++;
}
i++;
}
if(y<0)
printf("L1, str1 < str2\n");
else
printf("L2, str1 > str2\n");
}