strncmp() string handling functions - C-Tutorial

Latest

Friday, 7 October 2016

strncmp() string handling functions

C - strncmp() function:  The general format of strncmp() function is:
                       

Syntax:           strncmp(string1 , string2 , n);
           
Where, n is an integer argument.  Function compares atmost n characters of the given two strings.

/* EXAMPLE PROGRAM */

#include<string.h>

main()
{
            char str1[50],str2[50];
            clrscr();
            printf("\nEnter string 1:");
            gets(str1);
            printf("\nEnter string 2:");
            gets(str2);
            if((strncmp(str1,str2,3))==0)
                        printf(“\n Both Are Same”);
            else
                        printf(“\n Both Are Different”);

            printf("\nRESULT:%d",strncmp(str1,str2,3));

}

No comments:

Post a Comment