+ 1

HELP ME !!!

When i code , char decision[100]; And then scanf("%s", decision); and then i code if( decision == "yes") { goto back;} else if( decision == "no") { exit(0);} When i run this code, the code ia not working why? Please give me some solutions!

21st Oct 2020, 8:24 PM
hafidz ridwan cahya
hafidz ridwan cahya - avatar
5 Antworten
+ 3
You are using C type strings here so my answer will be C based. You can't make direct string comparisons like this. You should use strcmp(str1, str2) from the string.h library. Review strings in the C tutorial. https://www.sololearn.com/learn/C/2937/
21st Oct 2020, 8:40 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Can you add full code?
21st Oct 2020, 8:28 PM
Jayakrishna 🇮🇳
+ 1
Arrays in c are pointers actually so it you compare with a string literals.. Use strcmp function. You can see explanation in above link... Like if(!strcmp(decision, "yes")) Add string.h library
21st Oct 2020, 8:49 PM
Jayakrishna 🇮🇳
0
Wait sir
21st Oct 2020, 8:29 PM
hafidz ridwan cahya
hafidz ridwan cahya - avatar
21st Oct 2020, 8:33 PM
hafidz ridwan cahya
hafidz ridwan cahya - avatar