Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C program I want to know how can I add a whole name to if statement

I would like to know what is the problem with this code.
I want to right a name in the programming and if it’s correct give me "Let’s go" if it’s not give me go back.
I want to add Zay in if statement through right it in scanf. but it gives me an error I searched a lot but there is a problem, pls help me.

#include <stdio.h>
int main()
{
char name[15];
printf("Type name ");
scanf("%s",&name);
if(name == 'zay')
{
printf("Let's go, %s\n", name);
}
else
{
printf("go back, %s\n", name);
}
return 0;}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is wrong

if(name == 'zay')

you mean

if(strcmp(name, "zap") == 0)

see https://man7.org/linux/man-pages/man3/strcmp.3.html

and you need to include string.h

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading