Thread: Porblem In Coding !!!!

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    83

    Porblem In Coding !!!!

    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"); /* In this Line i get Error "Expression syntax is in function main() */
    }
    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.
    Last edited by RahulDhanpat; 02-11-2008 at 02:55 PM.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    ((a>=65 && a<=90)||(a>=97 && a<=122)

    PS. Instead of using magic numbers - better use constants like 'a' 'z' 'A' 'Z' - they make your code more readable
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Just editted few lines!

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Quote Originally Posted by RahulDhanpat View Post
    Just editted few lines!
    Are you using copy/paste from your Editor window?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by vart View Post
    ((a>=65 && a<=90)||(a>=97 && a<=122)

    PS. Instead of using magic numbers - better use constants like 'a' 'z' 'A' 'Z' - they make your code more readable

    Pleaase check my pgm once again... i also realised that i missed OR operator but after that i got one more problem....


    and i tried to use 'a' in this pgm but i got 18 errors and as i remove ' ' ..the error gone....can you explain y it happens?

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    from 97 we have small letters..
    Code:
    if(int a>=65 && <=90)
         printf("caps..");
    else if(chk for btween 97 & 122)
         printf('lowercase..");
    else if(chk for digits)
         printf("...");
    else
         printf("symbol")

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by vart View Post
    Are you using copy/paste from your Editor window?
    \

    Ya..... I m using Turbo c++ so i ahve to open each file in text editor and then copy my written text then paste it here. its really disgusting because Turbo C++ does not copy directly/.

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    where did you use 'a'?

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Is my pgm right? I mean i on the correct path? if yes then please give me solution of the lines i m getting error

  10. #10
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    with the following code I do not get any errors in VS2005
    Code:
    #include <stdio.h>
    int main(void)
    {
    	char a;
    	printf(" Enter Any Char in Capital or small case or any digit or any number");
    	scanf("&#37;c",&a);
    
    	if((a>=65 && a<=90)||(a>=97 && a<=122))
    	{
    		printf("CapsLock"); /* In this Line i get Error "Expression syntax is in function main() */
    	}
    	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");
    
    	return 0;
    }
    Are you sure you compiling the code you are posting?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by edesign View Post
    where did you use 'a'?
    \


    i used

    char 'a' ;

    ???????????????????????????????? I feel i did some bluder her????????????????????????

  12. #12
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    start using visual studio, just 2-3 steps u need to remember to compile your c program..

  13. #13
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    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

  14. #14
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by vart View Post
    with the following code I do not get any errors in VS2005
    Code:
    #include <stdio.h>
    int main(void)
    {
    	char a;
    	printf(" Enter Any Char in Capital or small case or any digit or any number");
    	scanf("%c",&a);
    
    	if((a>=65 && a<=90)||(a>=97 && a<=122))
    	{
    		printf("CapsLock"); /* In this Line i get Error "Expression syntax is in function main() */
    	}
    	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");
    
    	return 0;
    }
    Are you sure you compiling the code you are posting?
    yes but without the line i mention as error.......


    and i compikled your pgm in MS visual c++5
    and then turbo c++ both are giving 4 error and 1 warning msg??????????????????????

  15. #15
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

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