Notice anything funny about the code below compared to the output? I have the files saved and compiled without error or warning.
What's funny is it tells me when i=1 that the element and the *(arr->elements + i) are equal (namely STRING3), yet it's not going inside the if statement and printing "Found the element!" for that i value.
Here is my code:
void arr_remove(Array *arr, char *element)
{
printf("Searching for element %s\n", element);
for (int i = 0; i < arr->count; i++)
{
printf("i is %d and element is %s. Arr->elements is %s \n", i, element, *(arr->elements + i));
if (element == *(arr->elements + i))
{
printf("Found the element %s!!\n", element);
memmove(*(arr->elements + i), arr->elements + i + 1, sizeof(char *) * (arr->count - (i + 1)));
return;
}
}
fprintf(stderr, "Fprintf stderr: Array element not found\n");
}
Here is my console output:
Searching for element STRING3
i is 0 and element is STRING3. Arr->elements is STRING2
i is 1 and element is STRING3. Arr->elements is STRING3
i is 2 and element is STRING3. Arr->elements is STRING1
i is 3 and element is STRING3. Arr->elements is STRING4
Fprintf stderr: Array element not found
In other words, if I add this line
printf("Boolean condition %d\n", (element == *(arr->elements + 1)));
The output is
Boolean condition 0
Why is this and what can I do to fix it? Is it line ending (carriage return type stuff? They're both char pointer types. Any help would be appreciated!