+ 1

i am not getting the name. why? everytime it is showing 'i don't know'....

#include<stdio.h> void main() { char q[30]; printf("enter question="); scanf("%[^\n]",&q); switch(q[30]) { case 'what is your name?': printf("ans=lamia"); break; default: printf("I don't know"); break; } getch(); }

26th Mar 2018, 3:57 PM
lamia
lamia - avatar
7 ответов
+ 6
Sorry I had to do something for my son. https://code.sololearn.com/c6tP7EAQ3ib3
26th Mar 2018, 5:12 PM
John Wells
John Wells - avatar
+ 5
Do you plan on having multiple questions that must be typed in exactly or would you rather have a unique keyword (e.g. name, age, gender)?
26th Mar 2018, 4:15 PM
John Wells
John Wells - avatar
+ 4
You can't match a case of 'what is your name?' and you are testing the first character beyond the end of your array.
26th Mar 2018, 4:04 PM
John Wells
John Wells - avatar
+ 2
thanks a lot...u helped me a lot.....☺☺☺
26th Mar 2018, 5:57 PM
lamia
lamia - avatar
+ 1
can u please tell me the right way?
26th Mar 2018, 4:09 PM
lamia
lamia - avatar
+ 1
yeah
26th Mar 2018, 4:32 PM
lamia
lamia - avatar
+ 1
multiple questions
26th Mar 2018, 4:33 PM
lamia
lamia - avatar