Comparing Two Strings
Explore how to compare two strings in C using the standard strcmp function and by building a custom comparison function. Understand how return values indicate whether one string is greater than, less than, or equal to another. This lesson helps you grasp string comparison mechanics crucial for C programming.
We'll cover the following...
We'll cover the following...
The strcmp() function
The strcmp( ) function is used to compare whether or not two strings are equal. The basic syntax of the strcmp() function is given below:
int strcmp(const char *str2, const char *str1);
The order of passing base addresses to strcmp( ) must always be the target, followed by the source.
🧠 Quick question: Can we compare two strings using the following expression? ...