strcmp Function

  • It lexicographically compares two strings .
  • It returns an integer based on the outcome:

  • < 0 for str1 is less than str2
    0 for str1 is equal to str2
    > 0 for str1 is greater than str2

    Syntax:

      int strcmp(const char *str1, const char *str2);

    Example:

    
    
    
    
    
    #include <stdio.h>
    
    #include <string.h>
    
    
    
    int main(){
    
        char s[80]="passss";
    
        printf("Enter password: ");
    
        if(strcmp(s, "pass")) {
    
          printf("Invalid Password\n");
    
          return 0;
    
        }
    
        }
    Back