C - Using strcmp() function directly in if comparison

Description

Using strcmp() function directly in if comparison

Demo

#include <stdio.h>
#include <string.h>

int main()/*from w ww. j  a v a 2s  . co m*/
{
    char password[]="taco";
    char input[15];

    printf("Password: ");
    scanf("%s",input);

    if(strcmp(input,password)==0)
        puts("Password accepted");
    else
        puts("Invalid password. Alert the authorities.");

    return(0);
}

Result

Related Topic