Saturday, 24 August 2013

Where do I need to put the extra semicolon on line 17

Where do I need to put the extra semicolon on line 17

I'm new to programming in C and I'm trying to create a program that when a
user inputs their name, they are told what their sexual orientation is
randomly. Yet, gcc is erroring because I think I am missing a ; on line 17
which is: if(strcmp(x, arrayNames[i] == 0));. I am not too familiar with
strcmp(); but I am reading about it in K&R, just can't get my head around
it. Below is the entire code:
int main()
{
char *arrayNames[3]={"Jim", "Bob", "Dave"};
char *arrayOrient[3]={"straight", "gay", "bi"};
char x[100];
srand(time(NULL));
int size;
size = sizeof(arrayNames)/sizeof(arrayNames[0]);
int namesRand = rand() % size;
printf("Please enter your name: ");
scanf("%s", &x[0]);
int i;
for(i = 0; i < size; i++) {
if(strcmp(x, arrayNames[i] == 0));
{
printf("Hello %s, your orientation is: %s", x,
arrayOrient[namesRand]);
break;
}
else {
printf("Invalid name!");
}
}
return 0;
}
Any tips when using strcmp(); will be welcomed.

No comments:

Post a Comment