Now after this much i started to get output but still there are few problems... i m getting the digit working but when i put small case letter it says " CapsLock " and when input a symbol like " @ , ) .> somthing like this ..it says small case letter.????????????????
what may be the troubale...i check the ascii code and code written by me also... i feel everything is correct .??? can some one check my code and suggest something.l
you are printing caps for both the cases...understand the meaning of logical or??Code:if((a>=65 && a<=90)||(a>=97 && a<=122)) { printf("CapsLock"); /* In this Line i get Error "Expression syntax is in function main() */ }
Also, it will be better if you use nested if..else as i suggested earlier
use char constants such as a>='A'
or use like: if((int)a>=97...)
read earlier posts,if you can...try to correct errors suggested...
I also feel that i if i use nested if-else then i can do it easily but i bound to use logical operators as i m learning it now. ofocurse if -else will make it more easier but the code will look damn congested......
so i have to use logical oeprators and i feel there is something i missing in my logic....
i just divided this part in two parts and remove the else and braces.... and i started to get out put correctly for small cases.. and again i added OR operator in the logic line for Specail Symbol and i got the out put correct but still i m getting one " Warning While Compiling " i.e Constant out of range in camparison in funciton main() since it is just a warning even then my pgm worked.But if someone knows that why m i getitng this warning please educated me about that.. i m posting the code for that....
Code:#include <stdlib.h> #include <conio.h> #include <ctype.h> #include <stdio.h> main() { char a; printf(" Enter Any Char in Capital or small case or any digit or any number"); scanf("%c",&a); clrscr(); if((a>=65 && a<=90)) printf("CapsLock"); if((a>=97 && a<=122)) printf("Small Case letter"); if((a>='0' && a<='9')) printf(" Digit"); if((a>=0 && a<=46)||( a>=58 && a<=64)||( a>=91 && a<=96)||( a>=123 && a<=127)) /* In this line i get warning that " Constant out of range." */ printf("Speical Symbol"); getch(); }
Any suggesting for improvement on basic level for me.that will be very kind of u.and any comment over the warning i m getting in the above mention pgm.?
Get a better compiler, like Visual Studio.
Indent properly.
Use getchar() instead of getch().
Use int main, not main.
Don't use a >= some_number, do a >= 'my char' instead.
Very Nice advices ! this will really help me to write my pgm better ...
I just did not understand this thing.....Code:Don't use a >= some_number, do a >= 'my char' instead.
and which version of visual studio is easy to use and good.and does we need to study somthing else to operate visual stdio?
shd i go for visual stdio 5 express or 2008?
i have alredy Microsoft Visual 6 c++ ?
Pleae guide.
Whilst VS 6 isn't exactly new, there's nothing much wrong with it either. The only drawback is that it's not fully standards compliant. Not a HUGE deal. If you are going to upgrade, why not go for the latest - it's available free from MS, so what's there to stop you?
As for the comment on how to write if-statements: Make the code readable, if you want to see if it's a lower case char, why not compare withI assume that's what you are trying to do, but you are using numerical constants. I'm a pretty experienced programmer, but I still have to THINK about which letter is 97, 122, 65, 91, etc, etc.Code:if (c >= 'a' && c <= 'z')
And isn't everything that isn't a letter or digit a special character? So why not just say something like[Also, there is a better method for identifying character: If you include <ctype.h> and use "isdigit()", "isupper()", "islower()", you will get the same sort of effect that you are seeing right now, but it will also work in EBCDIC and other less common character sets where a..z may not actually be in one long row.]Code:else printf("special char");
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The program seems to be correct even though a bit ugly.
It surprised me the fact that people still use tools like TurboC.
Well, here goes a small remark on the warning you get.
[CODE]if((a>=0 && a<=46)||( a>=58 && a<=64)||( a>=91 && a<=96)||( a>=123 && a<=127))/CODE]
The last comparison of a<=127 gives you the warning.
If you read a little about the "C" built-in data types you will learn that there are some things
which are called specifiers. The most commonly used is 'unsigned', but it's brother 'signed' also exists because some people like to say exactly what a variable is. For "C" the default specifier on any integral( char, short, int, long ) type is 'signed'. Yup that's what you get when you write:
'a' has sign. And because it is of type 'char' it is 1 byte big.Code:char a; signed char a; /* The two declarations are equal */
Because 'a' is 1 byte big, there are 256 different values it can take.
Because 'a' has sign, the range of values it can take was decided to be from -128..127.
Therefore the compiler knows that 'a' is always less or equal to 127, thus warning you
about a possible error in your programs logic, which is a comparison that always holds true.
> For "C" the default specifier on any integral( char, short, int, long ) type is 'signed'.
Whether char is signed or unsigned by default is platform-dependent. I believe that's the only reason the keyword "signed" exists.
Edit:
> Because 'a' is 1 byte big, there are 256 different values it can take.
A C or C++ byte is only guaranteed to have at least 8 bits, not exactly 8. A signed char is guaranteed by the standard to be able to represent the values from -127 to +127, and an unsigned char the values from 0 to 255 (each of these ranges has enough possible values to imply at least 8 bits).
Last edited by robatino; 02-11-2008 at 10:38 PM.