Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

C programming/C reference/nonstandard/strncasecmp

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

C programming language offers a function called strncasecmp that compares the first n characters of a string with the other irrespective of the case of characters. strncasecmp is found in string.h header file. syntax int strncasecmp(const char *f1, const char *f2, size_t n ); The return value of this function is same as that of strcasecmp i.e it returns 0 if f1 and f2 are equal, a positive integer if f1 is found greater than f2 or a negative integer if f1 is found less than f2. Example # include <stdio.h> # include <string.h> # include <stdlib.h> int main(int argc, char *argv[]){ int i; if(argc != 4){ printf("bad input\n"); return 1; } i = strncasecmp(argv[1], argv[2], atoi(argv[3])); if (i == 0) printf("'%s' equals '%s'\n", argv[1], argv[2]); else if (i > 0) printf("'%s' is greater than '%s'\n", argv[1], argv[2]); else if (i < 0) printf("'%s' is less than '%s'\n", argv[1], argv[2]); return 0; }