Funktionen isxdigit () kontrollerar om ett tecken är ett hexadecimalt tecken (0-9, af, AF) eller inte.
Funktionsprototypen för isxdigit()
är:
int isxdigit (int arg);
Det definieras i rubrikfilen.
isxdigit () Parametrar
Den isxdigit()
funktionen tar ett enda tecken som en parameter.
Obs! Vid C-programmering behandlas tecken int
internt som värden.
C isxdigit () Returvärde
Om argumentet skickas till isxdigit()
är
- ett hexadecimalt tecken,
isxdigit()
returnerar ett heltal som inte är noll. - ett icke-hexadecimalt tecken
isxdigit()
returnerar 0.
Exempel 1: C isxdigit () -funktion
#include #include int main() ( char c = '5'; int result; // hexadecimal character is passed result = isxdigit(c); // result is non-zero printf("Result when %c is passed to isxdigit(): %d", c, isxdigit(c)); c = 'M'; // non-hexadecimal character is passed result = isxdigit(c); // result is 0 printf("Result when %c is passed to isxdigit(): %d", c, isxdigit(c)); return 0; )
Produktion
Resultat när 5 skickas till isxdigit (): 128 Resultat när M skickas till isxdigit (): 0
Exempel 2: Program för att kontrollera hexadecimalt tecken
#include #include int main() ( char c = '5'; printf("Enter a character: "); c = getchar(); if (isxdigit(c) != 0) ( printf("%c is a hexadecimal character.", c); ) else ( printf("%c is not a hexadecimal character.", c); ) return 0; )
Produktion
Ange ett tecken: ff är ett hexadecimalt tecken.