Reputation: 1
#include <stdio.h>
int main()
{
char name[10];
printf("Who are you? \n");
fgets(name,10,stdin);
printf("Good to meet you, %s.\n",name);
if(name=='spyros')
{
printf("Then you are here %s\n",name)
}
return(0);
}
Then i have warning warning: character constant too long for its type
Upvotes: 0
Views: 545
Reputation: 13
A char can only store 1 character not a set of characters, and by directly comparing the string to a character array won't work because of the null character
This will work , hope it helps
#include <stdio.h>
#include<string.h>
int main()
{
char name[10];
printf("Who are you? \n");
fgets(name,10,stdin);
printf("Good to meet you, %s.\n",name);
if(strcmp(name,"spyro"))
{
printf("Then you are here %s\n",name);
}
return(0);
}
Upvotes: 1