- C String Char Functions
- C String Char Functions
- C isalnum()
- C isalpha()
- C isblank()
- C iscntrl()
- C isdigit()
- C isgraph()
- C islower()
- C isprint()
- C ispunct()
- C isspace()
- C isupper()
- C isxdigit()
- C memchr()
- C memcmp()
- C memcpy()
- C memmove()
- C memset()
- C strcat()
- C strchr()
- C strcmp()
- C strcoll()
- C strcpy()
- C strcspn()
- C strerror()
- C strlen()
- C strncat()
- C strncmp()
- C strncpy()
- C strpbrk()
- C strrchr()
- C strspn()
- C strstr()
- C strtok()
- C strxfrm()
- C tolower()
- C toupper()
- C Input/Output Functions
- C Input/Output Functions
- C clearerr()
- C fclose()
- C feof()
- C ferror()
- C fflush()
- C fgetc()
- C fgetpos()
- C fgets()
- C fopen()
- C fprintf()
- C fputc()
- C fputs()
- C fread()
- C freopen()
- C fscanf()
- C fseek()
- C fsetpos()
- C ftell()
- C fwrite()
- C getc()
- C getchar()
- C gets()
- C perror()
- C printf()
- C putc()
- C putchar()
- C puts()
- C remove()
- C rename()
- C rewind()
- C scanf()
- C setbuf()
- C setvbuf()
- C snprintf()
- C sprintf()
- C sscanf()
- C tmpfile()
- C tmpnam()
- C ungetc()
- C vprintf()
- C vfprintf()
- C vsprintf()
- C vsnprintf()
- C vscanf()
- C vfscanf()
- C vsscanf()
- C Dynamic Allocation
- C Dynamic Allocation
- C calloc()
- C free()
- C malloc()
- C realloc()
- C Time/Date Functions
- C Time/Date Functions
- C asctime()
- C clock()
- C ctime()
- C difftime()
- C gmtime()
- C localeconv()
- C localtime()
- C mktime()
- C setlocale()
- C strftime()
- C time()
- C Programming Tutorial
- C Tutorial
- C Programming Examples
- C Programming Examples
- C Programming Test
- C Programming Test
- Give Online Test
- All Test List
C memcmp()
The memcmp() function compares the first count characters of the arrays pointed to by buf1 and buf2.
The memcmp() function returns an integer that is interpreted as indicated here in the following table :
Value | Meaning |
---|---|
Less than zero | buf1 is less than buf2 |
Zero | buf1 is equal to buf2 |
Greater than zero | buf1 is greater than buf2 |
memcmp() Syntax
Following is the syntax of the memcmp() function :
#include<string.h> int memcmp(const void *buf1, const void *buf2, size_t count);
memcmp() Example
Following program shows the outcome of a comparison of its two command line arguments :
#include<stdio.h> #include<string.h> #include<stdlib.h> int main(int argc, char *argv[]) { int outcome, len, l1, l2 if(argc!=3) { printf("Incorrect number of arguments."); exit(1); } /* find the length of shortest string */ l1 = strlen(argv[1]); l2 = strlen(argv[2]); len = l1 < l2 ? l1:l2; outcome = memcmp(argv[1], argv[2], len); if(!outcome) printf("Equal"); else if(outcome<0) printf("First less than second."); else printf("First greater than second."); getch(); }
« Previous Chapter Next Function »