C Programming
Computer Programming

C program to compare two string



Write a program in C to compare two string

\* C program to compare two string *\

# include < stdio.h >
# include < conio.h >
# include < string.h >
int   stringcpm(char str[], char str1[]) ;

int   main( )
{

char str[100], str1[100] ;
int length, ch, i ;
printf("\n Enter the First String : ") ;
scanf( "%s", str ) ;
printf( "\n Enter the Second String : ") ;
scanf( "%s", str1) ;
stringcpm( str, str1 ) ;
return (0) ;

}

int   stringcpm( char str[], char str1[] )
{

int i ;
i = 0 ;
while ( str[i] == str1[i] && str[i] != '\0' )
      i++ ;

if ( str[i] > str1[i] )
      printf("\n First String is greater then Second String !" ) ;
else if ( str[i] < str1[i] )
      printf("\n First String is less then Second String !" ) ;
else
      printf("\n Both String is equall !" ) ;
return (0) ;

}

Output of Program :

Output of C program to compare two string