Thread: problem with unicode

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732

    problem with unicode

    hello guys,
    how do i rectify this problem. i have been trying to use the below code to check the isdigit fucntion, but returns me 0 all the time.

    Code:
    #include<stdio.h>
    #include<ctype.h>
    #include<locale.h>
    
    int main()
    {
        setlocale(LC_CTYPE,"English");
        printf("%d",isdigit(4));
        getchar();
    }
    i am working on DEV-C++ on XP platform

    thanks in adavnce

    ssharish2005
    Last edited by ssharish2005; 04-02-2006 at 03:31 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Perhaps this?
    Code:
    printf("%d",isdigit('4'));
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    thanks Dave_Sinkula for you reply, what happends with the following

    Code:
    #include<stdio.h>
    #include<ctype.h>
    #include<locale.h>
    #include<stdlib.h>
    
    int main()
    {
        char sym[] = {"123"};
        setlocale(LC_CTYPE,"English");
        printf("%d",isdigit(atoi(sym)));
        getchar();
        return 0;
    }
    ssharish2005

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    The printed result would nonzero if the value 123 is an encoding for a digit. In ASCII, for example, digits have encoding values 48-57 inclusive.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    but it still prints me 0 even though after changing setting the locale to English. its not encoding in my case. does any one know why??am i setting the locale properly?? thank u very much guys

    ssahrish2005
    Last edited by ssharish2005; 04-02-2006 at 04:41 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well you posted incorrect code twice now, so how about posting the results from Dave's code?

    Or repost your latest effort.

    Because isdigit() is for '0' to '9', not 4 or 123 or any other integer value you get.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Because isdigit() is for '0' to '9', not 4 or 123 or any other integer value you get.
    thanks salem for your reply. it seems that isdigit works only for unsigned char. but i was trying to check with a set of unsigned char thats the reason i posted with the set of char 123. its seems that it can work only a single unsigned char. i think i got the answer. thanks salem and Dave. sorry about my miss understanding in the above post.

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM