strncmpi

Discussion in 'C' started by raagasri, Nov 2, 2009.

  1. raagasri

    raagasri New Member

    Joined:
    Nov 2, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include <stdio.h>
    int main(int argc, char** argv)
    {
    	char acNamme[10];
    	char acPrint[10];
    	int iCmp;
    	char acName[]= "what is your name";
    	printf(acName);
    	scanf("%s \n", &acNamme);
    	printf("%s \n", acNamme);
    	gets(acPrint);
    	printf("%s",acPrint);
    	iCmp = strncmpi(acNamme,acPrint,3);
    	if(iCmp==0)
    	{
    		printf("Comparison success");
    	}
    	else
    	printf("not success");
    }
    why i get an error "undefined reference to 'strncmpi' "
     
    Last edited by a moderator: Nov 3, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Oops, you forgot to read the posting guidelines. They're really not that difficult to miss and quite easy to read.
     
  3. murugaperumal

    murugaperumal New Member

    Joined:
    Feb 20, 2010
    Messages:
    15
    Likes Received:
    1
    Trophy Points:
    0
    Dear Friends,

    There is no function like "strncmpi" in C . You should you the stcncmp function.


    iCmp = strncmp(acNamme,acPrint,3);
     
  4. vivekraj

    vivekraj New Member

    Joined:
    Feb 23, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    There is no such function called strncmpi in C.

    If you want to compare the strings with case sensitive.Then,you use strncmp function.


    If you want to compare the strings ignoring case.Then,you use strncasecmp function which is similar to strncmp but ignores the case during comparison.
     
  5. thillai_selvan

    thillai_selvan New Member

    Joined:
    Feb 20, 2010
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Are you trying to write your own strncmp function to perform case insensitive comparison?
     
  6. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    You can use this header file and save it as strncmpi.h

    Code:
    #include "autocfg.h"
    #include "compat/strncmpi.h"
    #include <ctype.h>
    
    int strncmpi(const char *a1, const char *a2, unsigned size) {
    	char c1, c2;
    	/* Want both assignments to happen but a 0 in both to quit, so it's | not || */
    	while((size > 0) && (c1=*a1) | (c2=*a2)) {
    		if (!c1 || !c2 || /* Unneccesary? */
    			(islower(c1) ? toupper(c1) : c1) != (islower(c2) ? toupper(c2) : c2))
    			return (c1 - c2);
    		a1++;
    		a2++;
    		size--;
    	}
    	return 0;
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice