Hello there,
I am trying to compare two strings, namely:
str1 = "hello\0"
str2 = "hello\200"
When I input the above two strings into strcmp, the output correctly shows that the output integer of str2 is greater than str1.
I dont understand why, when I compare my strings, when I access the 6th element, str1[6] or str[6], they give me different answers. What is being referenced?
Str1[6] returns nothing whilst str2[6] return a funny C character.
I understand that a backslash suggests, refers to an "escape sequence", but I am not sure how to compare the strings whilst ignoring escape sequences... If i compare str1[6] to '\\', it also does not correspond.
Thanks for your help!
My code is as follows:
Code:
#include <stdio.h>int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && ((s1[i] && s2[i]) != '\0'))
{
printf("s1[%d] == %c\ns2[%d] == %c\n\n", i, s1[i], i, s2[i]);
if (s1[i] != '\0')
i++;
}
printf("s1[%d] == %c\ns2[%d] == %c\n\n", i, s1[i], i, s2[i]);
return ((int)s1[i] - (int)s2[i]);
}