0
#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

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.