#define MAX 5
#define LEN 40
void main(void)
{
int dex;
int enter=0;
char name[40];
static char list[MAX][LEN]={ "Muzammil", "Nigel", "Katrina",
"Alistair" };
printf("Enter your name:"):
gets(name);
for(dex=0;dex<MAX;dex++)
if(strcmp(&list[dex][0],name)==0)
enter = 1;
if(enter==1)
printf("You may enter, oh honored one.");
else
printf("Guards! Remove this person!");
}
Output:
There are two possible outcomes when you interact with this program. Either your name is on the list:
Enter your name: Muzammil
You may enter, oh honored one.
or it isn't:
Enter your name: George
Guards! Remove this person!
#define LEN 40
void main(void)
{
int dex;
int enter=0;
char name[40];
static char list[MAX][LEN]={ "Muzammil", "Nigel", "Katrina",
"Alistair" };
printf("Enter your name:"):
gets(name);
for(dex=0;dex<MAX;dex++)
if(strcmp(&list[dex][0],name)==0)
enter = 1;
if(enter==1)
printf("You may enter, oh honored one.");
else
printf("Guards! Remove this person!");
}
Output:
There are two possible outcomes when you interact with this program. Either your name is on the list:
Enter your name: Muzammil
You may enter, oh honored one.
or it isn't:
Enter your name: George
Guards! Remove this person!
0 comments:
Post a Comment