Can you compare two strings like string1==string2? Why do we need strcmp()?
Do you think this will work?
No!, strings in C cannot be compared like that!.Code:if(string1 == string2) { }
The == operator will end up comparing two pointers (that is, if they have the same
address). It wont compare the contents of those locations. In C, strings are represented
as arrays of characters, and the language never manipulates (assigns, compares, etc.)
arrays as a whole.
The correct way to compare strings is to use strcmp()
Code:if(strcmp(string1, string2) == 0) { }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks