Comparison of Isalnum () function and Isalpha () function in C language using _c language

Source: Internet
Author: User

C language Isalnum () function: To determine whether a character is an English letter or a number
header file:

#include <ctype.h>

Isalnum () is used to determine whether a character is an English letter or a number, equivalent to Isalpha (c) | | IsDigit (c), whose prototype is:

  int isalnum (int c);

"Parameter" C is the character you want to detect.

"Return value" if the parameter C is a letter or a number, if C is 0 ~ 9 A ~ z a ~ z returns not 0, otherwise return 0.

Note that isalnum () is a macro definition, not a true function.

"Instance" finds characters in the STR string that are English letters or numbers.

#include <ctype.h>
Main () {
  char str[] = "123c@ #FDsP [E?";
  int i;
  for (i = 0; Str[i]!= 0; i++)
    if (Isalnum (str[i)))
      printf ("%c be an alphanumeric character\n", str[i));

Output results:

1 is a apphabetic character
2 is a apphabetic character 3 is a apphabetic character C is a
apphabetic Char Acter
F is a apphabetic character
D is a apphabetic character S is a apphabetic
character
P is a appha Betic character
E is a apphabetic character

C language Isalpha () function: To determine whether a character is an English letter
header file:

#include <ctype.h>

Isalpha () is used to determine whether a character is an English letter, equivalent to Isupper (c) | | Islower (c), whose prototype is:

  int isalpha (int c);

"Parameter" C is the character that needs to be detected.

return value if parameter C is an English letter (a ~ z a ~ z), returns a value other than 0, otherwise returns 0.

Note that Isalpha () is a macro definition, not a true function.

"Instance" finds characters in the STR string that are English letters.

#include <ctype.h>
Main () {
  char str[] = "123c@ #FDsP [E?";
  int i;
  for (i = 0; Str[i]!= 0; i++)
    if (Isalpha (str[i)))
      printf ("%c be an alphanumeric character\n", str[i));

Execution results:

C is a apphabetic character
F is a apphabetic character D is a apphabetic
character S is a
apphabetic C Haracter
P is a apphabetic character
E is a apphabetic character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.