Table of Contents
This guide covers the function memcmp ()() in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
Declare the Function Memcmp ()() in C
Below is the declaration for memcmp () in C:
int memcmp ( const void * str1 , const void * str2 , size_t n )
Parameters
Str1 - This is the pointer to a memory block.
Str2 - This is a pointer to a memory block.
n - This is the number of bytes to be compared.
Returns the Value
If
If the value> 0 is returned, this function indicates that str2 is shorter than str1.
If the value = 0 is returned, this function indicates that str1 is equal to str2.
For Example
The following C program illustrates the usage of memcmp () in C:
#include #include int main () { char str1 [ 15 ]; char str2 [ 15 ]; int ret ; memcpy ( str1 , "abcdef" , 6 ); memcpy ( str2 , "ABCDEF" , 6 ); ret = memcmp ( str1 , str2 , 5 ); if ( ret > 0 ) { printf ( "Chuoi str2 la ngan hon chuoi str1" ); } else if ( ret < 0 ) { printf ( "Chuoi str1 la ngan hon chuoi str2" ); } else { printf ( "Chuoi str1 la bang chuoi str2" ); } return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Function memchr () in C
Next lesson: Function memcpy () in C
FAQ
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Reader Comments 0
Sign in with email or Google to join the discussion.