Link to home
Start Free TrialLog in
Avatar of zizi21
zizi21

asked on

isalnum

Hi,

Could anyone tell me the difference between isalnum and a-z ||A-Z||0-9 ?

Thanks!
Zizi
Avatar of Anthony2000
Anthony2000
Flag of United States of America image

Hi Zizi,

What do you mean the difference? I believe that isalnum will return true if the value passed is in the range you listed.
Are you refereing to a regular expression?
Avatar of zizi21
zizi21

ASKER

Hi Anthony,

It is just that I thought of using the isalnum which I thought is a function that checks for alphabets and numeric values only..

Is is correct to assume that alphabets are A-Z, a-z and numbers is 0-9. The reason i ask is, lets say , I have another language installer on my machine. An 'A' in my language would be displayed differently, does isalnum still consider it as 'A'.

When it is says alphabets, does it means English ascii values...

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zizi21

ASKER

Hi infinity,

What do you mean by locale...It is just that currently isalnum is giving me true for empty space as well..that's why i am very confuse..
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you use a debugger to look at the value or print out the value using something like:

printf("0x%x", c);  // where c contains the value that you are passing to isalnum

Avatar of zizi21

ASKER

Got it..I was adding the nul character...
by the way, which would u recommend, using A , a way or isalnum way ? thanks
>> which would u recommend, using A , a way or isalnum way ?

isalnum is a very easy way to determine whether a character is an alphanumeric character or not ... so it's usually the recommended way.

However, you didn't explain what you plan to do with this, so maybe your situation requires a different approach. Can you explain what you are trying to do ?
Avatar of zizi21

ASKER

I am actually a beginner..My teacher taught the functions in class, only definitions were given. So, i thought, maybe I could learn more if I try doing it.. isspace, isalnum, isalpha, isdigit  

and the definition said isalnum is for alphanumeric characters but my friend told me that , if you use different language, you are not necesary going to get alphanumeric characters..So, it is better to use A || a way...I did few simple programs to test these out.

I guess, my friend was wrong.

What i am trying to do is to test whether the word is alphanumeric.  Thank you very much...

Avatar of zizi21

ASKER

I read the link above.

Sorry, if i am repeating this alphanumeric means any English alphabets A-Z or a-z or 0-9. Any others does not fall in alphanumeric.

Thanks
>> So, i thought, maybe I could learn more if I try doing it..

That's a very good idea :)

Take a look at the URL I posted ... It points to a reference for the isalnum and other similar functions. You'll find a lot more information, including example code there.


>> but my friend told me that , if you use different language, you are not necesary going to get alphanumeric characters

If your locale is properly set for that different language, then isalnum should handle that fine.


>> So, it is better to use A || a way...

The default locale is already using the normal A-Za-z alphabet. So, unless your system has a different locale configured, and you want to be able to check for A-Za-z, just go with isalnum.


>> What i am trying to do is to test whether the word is alphanumeric.

Then you just need to call isalnum for every letter in the word. If you want, you can show us your code, and we can take a look at it to see if it's ok.
>> Sorry, if i am repeating this alphanumeric means any English alphabets A-Z or a-z or 0-9. Any others does not fall in alphanumeric.

As I said, it depends on the locale. The default locale will indeed use the default A-Za-z alphabet, but when a different locale is set, different characters can be identified as alphanumeric.

A quote from the site I linked to :

        "Notice that what is considered a letter may depend on the locale being
        used; In the default C locale, what constitutes a letter is what returns
        true by either isupper or islower."

and for isupper :

        "Notice that what is considered a letter may depend on the locale being
        used; In the default C locale, an uppercase letter is any of: A B C D E F
        G H I J K L M N O P Q R S T U V W X Y Z."

(similar for islower).

As you see, they explicitly say that it depends on the locale.

In any case, you shouldn't have to worry about this since you're only learning. Just go with isalnum, and you should be fine.
Avatar of zizi21

ASKER

I am sorry if i am asking too much questions. I am very curious too know this,,,i checked at the control panel and i went to regional, how do i find whether the C locale is used.

What country are you in ? And what language is your operating system set to ?

>> how do i find whether the C locale is used.

You can use this piece of code :

    #include <stdio.h>
    #include <locale.h>
   
    int main(void) {
      fprintf(stdout, "current locale : %s\n", setlocale(LC_ALL, 0));
      return 0;
    }

See this reference page for more info :

    http://www.cplusplus.com/reference/clibrary/clocale/setlocale.html
Avatar of zizi21

ASKER

Hi,

I am in Singapore. Some use Windows but mostly unix is used.

thank you very much. I would read more on it...
Avatar of zizi21

ASKER

i just checked it with the code above and it is C. thank you