0

After take string as an input from user , How to apply that inputed string in if-else statement ???

include <stdio.h> int main() { int choice; char name[15]; printf("\n\n>>>DIGITAL PERIODIC TABLE"); printf("\n1.ENTER BY NAME"); printf("\n2.ENTER BY SYMBOL"); printf("\n\nENTER YOUR CHOICE : "); scanf("%d",&choice); printf("\n\nENTER NAME :- "); scanf("%s",name); //I don't want whitespaces so not used gets() function okk.... printf("\n\n you entered :- %s",name); if(name=="hydrogen") printf("\n\n ELEMENT FOUND...."); else if (name=="lithium") printf("\n\nLITHIUM ELEMENT FOUND.."); else printf("\n\nNOT FOUND ANY ELEMENT"); //I am trying this code but its not working after entered the element name as hydrogen... //this program only show "Not found any element" /*Should all the element name declares in the char array before running the program...i tried it also but not found any result...*/ Help pls...

3rd Aug 2020, 2:36 PM
Bhupendra Singh Sisodia
Bhupendra Singh Sisodia - avatar
2 Antworten
+ 7
Use `strcmp` function for string comparison 👇 http://www.cplusplus.com/reference/cstring/strcmp/
3rd Aug 2020, 2:47 PM
Ipang
0
No problem glad if it helps 👌 DM doesn't work for me, I can only read not reply.
3rd Aug 2020, 4:01 PM
Ipang