<ctype.
h>
The <ctype.h> contains prototypes for a dozen character classification
functions. All of these functions except isdigit and isxdigit are locale-
specific; their behavior may change if the locale changes.
Tests In the form int isfunc(int);
Return a nonzero number for true and zero for false.
isalnum test for alphanumeric character
isalpha Test for alphabetic character
isblank Test for blank character (new in C99)
iscntrl Test for control character
isdigit Test for digit. Not locale-specific.
isgraph Test for graphic character, excluding the space
character.
islower Test for lowercase character
isprint Test for printable character, including the space
character.
ispunct Test for punctuation character
isspace Test for any white space character
isupper Test for uppercase character
isxdigit Test for hexadecimal digit. Not locale-specific.
This is the program:
#include <ctype.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void main ( )
{
int test;
char *ans[2] = {" not ", ""};
for (test = 1; test <4; test++)
{
printf ("\n\n\nThe value %02x is :\n", test);
Prepared by: Shekhar Mehta Page 1
printf (" %salphanumeric\n", ans[(isalnum(test) != 0)]);
printf (" %sa letter\n",ans[(isalpha(test) != 0)]);
printf (" %sascii\n",ans[(__isascii(test) != 0)]);
printf (" %sa control\n",ans[(iscntrl(test) != 0)]);
printf (" %sa letter,underscore or digit\n",ans[(__iscsym(test) != 0)]);
printf (" %sa letter or underscore\n",ans[(__iscsymf(test) != 0)]);
printf (" %sa digit\n",ans[(isdigit(test) != 0)]);
printf (" %sprintable/ not a space\n",ans[(isgraph(test) != 0)]);
printf (" %slower case\n",ans[(islower(test) != 0)]);
printf (" %sprintable\n",ans[(isprint(test) != 0)]);
printf (" %sa punctuator\n",ans[(ispunct(test) != 0)]);
printf (" %swhite space\n",ans[(isspace(test) != 0)]);
printf (" %supper case\n",ans[(isupper(test) != 0)]);
printf (" %sa hexadecimal digit\n",ans[(isxdigit(test) != 0)]);
printf ("\n* Press a key for the next value*\n");
getch ( );
}
}
The Output is:
The value 01 is :
not alphanumeric
not a letter
a control
not a digit
not printable/ not a space
not lower case
not printable
not a punctuator
not white space
not upper case
not a hexadecimal digit
* Press a key for the next value*
The value 02 is :
not alphanumeric
Prepared by: Shekhar Mehta Page 2
not a letter
a control
not a digit
not printable/ not a space
not lower case
not printable
not a punctuator
not white space
not upper case
not a hexadecimal digit
* Press a key for the next value*
The value 03 is :
not alphanumeric
not a letter
a control
not a digit
not printable/ not a space
not lower case
not printable
not a punctuator
not white space
not upper case
not a hexadecimal digit
* Press a key for the next value*
Prepared by: Shekhar Mehta Page 3
Process.h
_c_exit, _cexit, _getpid, onexit, atexit
Prototype
void _c_exit(void);
void _cexit(void);
int _getpid(void);
Description
The _c_exit and _cexit functions perform cleanup operations and return
without terminating the calling process. The _c_exit function performs a
quick C library termination procedure and returns to the caller without
processing registered exit functions (atexit or _onexit) or flushing buffers.
In contrast, the _cexit function performs a complete C library termination
procedure by calling registered exit functions in LIFO order, flushing all I/ O
buffers, and closing all open streams before returning to the caller.
Return Value
None
The _getpid function returns the process identification number (process ID)
for the calling process. The ID uniquely identifies a process.
Return Value
Both functions return the process ID. There is no error return.
Example
/* Example for _c_exit and _cexit
Also demonstrates atexit
*/
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
void cdecl near_exit_function(void)
{
Prepared by: Shekhar Mehta Page 4
printf (" In the atexit function\n");
}
void main()
{
atexit (near_exit_function);
_c_exit();
printf (" Shouldn't have called the atexit function yet.\n");
_cexit();
printf (" Should have called the atexit function now.\n");
}
/* Example for _getpid */
void main ()
{
printf (" The process id of this program is%d\n", getpid ());
}
getch();
}
The Output is:
Shouldn't have called the atexit function yet.
In the atexit function
Should have called the atexit function now.
In the atexit function
The process id of this program is 7640
Prepared by: Shekhar Mehta Page 5
Math.h
Pow , Sqrt , exp , log ,pow10
Declaration
double pow(double x, double y);
double log(double x);
double log10(double x);
double sqrt(double x);
double exp(double x);
Description
pow and powl calculate x**y.
log and logl calculate the natural logarithm of x.
sqrt calculates the positive square root of the input value.
exp calculates the exponential function e**x.
þ log10 and log10l calculate the base 10 logarithm of x.
Example:
#include <stdio.h>
#include <math.h>
#include<conio.h>
int main(void)
{
double result,res,re;
double x = 4.0,y=8.6872,z= 4.0,p=3.0;
clrscr();
result = exp(x);
printf("\n'e' raised to the power of %lf (e ^%lf) = %lf\n",x, x, result);
res = log(y);
printf("\nThe natural log of %lf is %lf\n", y, res);
re = sqrt(z);
printf("\nThe square root of %lf is %lf\n", z, re);
Prepared by: Shekhar Mehta Page 6
printf("\n%lf raised to %lf is %lf\n", x, y,pow(x, y));
printf("\nTen raised to %lf is %lf\n", p,pow10(p));
getch();
return 0;
}
The Output is:
'e' raised to the power of 4.000000 (e ^ 4.000000) = 54.598150
The natural log of 8.687200 is 2.161851
The square root of 4.000000 is 2.000000
4.000000 raised to 8.687200 is 169908.676379
Ten raised to 3.000000 is 1000.000000
Prepared by: Shekhar Mehta Page 7