0

It can't getting print the apple where which is true

#include<stdio.h> void main() { char ch,ch1,x,y,z,u; printf("x = apple\ny = oranges\nz = grapes\nu = bananas\n"); printf("Enter the character = "); scanf("%c",&ch); if(ch==x){ printf("Apple"); } }

25th Apr 2021, 6:40 PM
vivek_sai 0449
vivek_sai 0449 - avatar
5 Answers
+ 2
You must assign value to variables if you want to check their values. printf just prints something on the screen, "x = apple" is not declararion, you are telling printf to print it, nothing more. Btw you cannot assign strings to char. You have to make char pointer or char array (string), and even if you will do, you can't compare these strings with == operator. There is that library <string.h>, which includes lots of useful function to manipulate strings, it should help you if you'll check it (find that library on the internet)
25th Apr 2021, 6:59 PM
Michal Doruch
+ 1
Can any one explain
25th Apr 2021, 6:41 PM
vivek_sai 0449
vivek_sai 0449 - avatar
+ 1
You have not assigned any value to x. You’ve only printed that out. Assign all those variables.
25th Apr 2021, 7:01 PM
Jerry Hobby
Jerry Hobby - avatar
0
#include<stdio.h> #include<string.h> void main() { printf("Picking of fruit\n"); printf("PICK ANY TWO FRUITS FROM \nAPPLE\nBANANA\nGRAPE\nORANGE\n"); char "apple","orange","banana","grape"; char i[10]; int n; gets(i); n = 0; while(n<2) { if (i=="apple"||i=="Apple") { printf("U CAN PICK BANANA also\n"); } else if(i=="orange"||i=="Orange") { printf("U CAN PICK GRAPES also\n"); } else if(i=="grapes"||i=="Grapes") { printf("U CAN PICK BANANA also\n"); } else if(i=="banana"||i=="Banana") { printf("U CAN PICK APPLE also\n"); } n+=1; if(n<2) { gets(i); } } } '
26th Apr 2021, 4:53 AM
vivek_sai 0449
vivek_sai 0449 - avatar
0
See it let me know
26th Apr 2021, 4:53 AM
vivek_sai 0449
vivek_sai 0449 - avatar