Thread: Porblem In Coding !!!!

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by edesign View Post
    no you cant do it like that..
    when you write char a or int b
    you are defining a variable,which is of datatype char or int respectively...you need to follow some rules to give a variable name...you can't have a variable named a-b, or 'a'..why you wanted to use char 'a'?

    also your logic is wrong..
    for ascii values between 97 to 122 we have small letters...
    Ask if still in doubt
    i have checked my above mentioned pgm , their i mentioned 97 to 122 is for small case letter??? you can see that????

    but agian the problem remains there..... what will be the soluiton of the error i m getting...check the pgm code once agin.

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by vart View Post
    Look at this sample
    Code:
    if((a>='0' && a<= '9'))
       printf(" Digit");
    Isn't it more readable?
    Make the rest of your checks the same way
    Yor are correct man...... and also i started to experiecnce the real meaning of "Readable" word... i have heard it 100 times.. but never experience it..

    Thanks alot

  3. #18
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    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

  4. #19
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    Code:
    if((a>=65 && a<=90)||(a>=97 && a<=122))
    	{
    		printf("CapsLock"); /* In this Line i get Error "Expression syntax is in function main() */
    	}
    you are printing caps for both the cases...understand the meaning of logical or??
    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...)

  5. #20
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by RahulDhanpat View Post
    Question is :- Any char is inter thorugh keyboard ,write a pgm to determine whether the char is enter is capital , small case letter, digit or a symbol.
    NOTE:- using logical operators only or conditional operators
    i wrote a pgm for that... and there is one error..and one
    warning and even i do not know..the pgm is correct or not... please check and help me.

    here is the code..

    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("&#37;c",&a);
    clrscr();
    if((a>=65 && a<=90)||(a>=97 && a<=122))
    {
    printf("CapsLock"); 
    }
    else
    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();
    }
    Please help.
    Once again i have quote my question and the code here for ease of finding it.
    Last edited by RahulDhanpat; 02-11-2008 at 03:06 PM.

  6. #21
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    read earlier posts,if you can...try to correct errors suggested...

  7. #22
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by edesign View Post
    Code:
    if((a>=65 && a<=90)||(a>=97 && a<=122))
    	{
    		printf("CapsLock"); /* In this Line i get Error "Expression syntax is in function main() */
    	}
    you are printing caps for both the cases...understand the meaning of logical or??
    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...)
    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....

  8. #23
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    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("&#37;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();
    
    
    }

  9. #24
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    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.?

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by Elysia View Post
    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 ...

    Code:
    Don't use a >= some_number, do a >= 'my char' instead.
    I just did not understand this thing.....
    and which version of visual studio is easy to use and good.and does we need to study somthing else to operate visual stdio?

  12. #27
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    shd i go for visual stdio 5 express or 2008?
    i have alredy Microsoft Visual 6 c++ ?

    Pleae guide.

  13. #28
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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 with
    Code:
    if (c >= 'a' && c <= 'z')
    I 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.

    And isn't everything that isn't a letter or digit a special character? So why not just say something like
    Code:
    else printf("special char");
    [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.]

    --
    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.

  14. #29
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    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:
    Code:
    char a;
    signed char a;  /* The two declarations are equal */
    'a' has sign. And because it is of type 'char' it is 1 byte big.
    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.

  15. #30
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    > 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  2. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 07:09 AM
  3. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 02:26 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 04:32 PM