No :(
Printable View
No :(
I get this error when it tries to coimpile it :
Code:strings.c(5) : Error: need explicit cast to convert
from: char *
to : int
if(strcmp(name, guess)==0) {
^
strings.c(19) : Error: need explicit cast for function parameter 1 to get
from: int *
to : char const *
--- errorlevel 1
U are comparing with the int array which is not right. Perhaps it should have been a 2D string. And even more the strcmp string is expecting the char * not int * or char[][].Code:int name[] = {"EDDIE","BEN","DAVE"};
So above code should be
And perhaps you now should change your code to suite he above statmentCode:char name[][20] = {"EDDIE","BEN","DAVE"};
ssharish2005Code:#include <stdio.h>
#include <string.h>
int main()
{
char name[][20] = {"EDDIE","BEN","DAVE"};
int i;
char guess[10];
int correct = 0;
char * p;
printf("Enter a name in uppercase: ");
while(!correct)
{
fgets(guess ,10, stdin);
p = strchr(guess, '\n');
if ( p )
*p = 0;
for(i=0;i<3;i++)
{
if(strcmp(name[i], guess)==0)
{
printf("Correct!\n");
correct = 1;
getchar();
return 0;
}
}
printf("Try again: ");
}
getchar();
return 0;
}
The compiler tries to tell you that a pointer to an int is not a c-string.
You could try to declare name like this
Of corse you would need some kind of loop to find out if any of the names matches.Code:char name[][6] = {"EDDIE","BEN","DAVE"};
Kurt
ssharish and kurt , thank you VERY much . That solves my problem perfectly :)