So I am trying to compare if a line in file is what I expect but even though when I print to console the first line of a file and what I expect and they look exactly the same THEY are not passing my strcmp test. This is how I test the first line of a file and what I expect:
char currentLine[MAXIMUM_LINE_LENGTH + 1]; // + 1 for terminating char
fgets(currentLine, MAXIMUM_LINE_LENGTH, inputFile);
assertCharArrayEquals(currentLine, "00000010000100011001000000100000\n");
My method assertCharArrayEquals looks like:
void assertCharArrayEquals(char *actualCharArray, char *expectedCharArray) {
if (strcmp(actualCharArray, expectedCharArray) == 0) {
printf("PASS: assertCharArrayEquals(%s, %s)\n", actualCharArray, expectedCharArray);
} else {
printf(">>>>>>>FAIL: assertCharArrayEquals(%s, %s)\n", actualCharArray, expectedCharArray);
}
}
and my output to console looks like:
>>>>>>>FAIL: assertCharArrayEquals(00000010000100011001000000100000
, 00000010000100011001000000100000
)
According to your output, actualCharArray
ends with a newline character ('\n'
), whereas expectedCharArray
does not; therefore, they are not considered equal by strcmp
.