Code:#include<stdio.h> #include<conio.h> main() { char month; clrscr(); printf("input month"); scanf("%s',month); if (month==january) printf("yes"); else printf("no"); getch(); return(0); }
Code:#include<stdio.h> #include<conio.h> main() { char month; clrscr(); printf("input month"); scanf("%s',month); if (month==january) printf("yes"); else printf("no"); getch(); return(0); }
No for many many reasons.
1 - You don't need conio.h. It's a nonstandard header, and for what you're using it for, you may as well just use getchar. It just happens to be in stdio.h, which you're already including anyway.
2 - Why are you not including a return type for main? I will never understand why people decide it's fine to leave off the return type for main when they include it with all the rest of their functions. The return type for main, by the way, is an int. Nothing else.
3 - 'month' is a single character, not more than one. That would be an array of characters.
4 - Your call to scanf is using the scan code for a string, but you're trying to read into a single character. You either need to change what you're reading into, or use the correct scan code. Or both. Also, the arguments for scanf are all pointers. This means you need to either provide the address of a single variable as an argument, or a pointer to said variable, or the name of an array, etc.
5 - You can't compare strings with the equality operator. Of course in this case, you don't actually have a string, so if there actually was a variable called january it would be correct. However, what you really want is:Of course you'll need to use the correct header for said string function.Code:if( strcmp( somearray, "january" ) == 0 )
Quzah.
Last edited by quzah; 02-03-2006 at 12:34 AM. Reason: copy-paste disaster
Hope is the first step on the road to disappointment.
http://cboard.cprogramming.com/showthread.php?t=75296
We already told you all of your errors and you didn't listen at all. We even rewrote your code for you. Stop with the new topics if you aren't going to take people's advice.
Sent from my iPadŽ
Closed for not listening to previous thread.