Categories
Why is the Character Array not equal to a normal string?
char var[] = {'a', 'b', 'c', '\0'}; char var2[] = "abc"; if (var == var2) { printf("%s\n", "all is ok !"); }
Answer the question
In order to leave comments, you need to log in
Because your code is comparing pointers (memory addresses for strings in var and var2). To compare strings, there are the strcmp functions (and its variations).
Didn't find what you were looking for?
Ask a Question
731 491 924 answers to any question