You are here: Home / Topics / Program to compare Strings in C++ (strcmp function in C++)

Program to compare Strings in C++ (strcmp function in C++)

Filed under: C++ on 2023-08-20 14:10:21

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

int main()
{
char name[6][10]={
    "shyam",
    "dheerendra",
    "praveen",
    "nitesh",
    "gaurav",
    "bajpai"
};
char yourname[10];
int a, m=0, i;
printf("Enter your name to access this software");
scanf("%s", yourname);
m=0;
for(i=0; i<6; i++)
{
 a=strcmp(&name[i][0], yourname);
 if(a==0)
 {
  m=1;
  break;
 }
}

if(m==1)
printf("\n You are authorised to access this software.");
else
printf("\n You are not authorised to access this software. Kidnly contact your administrator.");
}

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.