C Functions
This is a summary of the useful functions I have come across. I have grouped
the functions by library. If you want an alphabetical list, please use the
master index. Please refer to a manual
for a complete list of ANSI functions.
-
The ANSI library is declared in the following header files.
assert.h
-
assert
ctype.h
-
isalnum
Checks whether a character is alphanumeric (A-Z, a-z, 0-9)
-
isalpha
-
iscntrl Checks whether
a character is a control character or delete ( decimal 0-31 and 127)
-
isdigit Checks whether
a character is a digit (0-9)
-
isgraph Checks whether
a character is a printable character, excluding the space (decimal 32)
-
islower Checks whether
a character is a lower case letter (a-z).
-
isprint Checks whether
a character is printable (decimal 32-126).
-
ispunct Checks whether
a character is punctuation (decimal 32-47, 58-63, 91-96, 123-126)
-
isspace Checks whether
a character is white space - space, CR HT VT NL, FF.
-
isupper Checks whether
a character is an upper case letter (A-Z).
-
isxdigit Checks whether
a character is hex digit (0-9, A-F, a-f).
-
toupper Converts a lowercase
character to uppercase.
-
tolower Convert an uppercase
character to lowercase.
errno.h
-
errno
float.h
-
No functions are declared in stddef.h.
limits.h
-
No functions are declared in stddef.h.
locale.h
-
setlocale
-
math.h
-
acos
-
asin
-
atan
-
atan2
-
ceil smallest integral value not less
than x
-
cos Cosine.
-
cosh
-
exp
-
fabs absolute value of floating-point
number
-
floor largest integral value not greater
than x
-
fmod floating-point remainder function
-
frexp
-
ldexp
-
log
-
log10
-
modf
-
pow Raise a number by
a power.
-
sin The sine of an integer.
-
sinh
-
sqrt Square root of
a number.
-
tan Tangent.
-
tanh Hyperbolic tangent.
setjmp.h
-
setjmp
-
longjmp
signal.h
-
signal
-
raise
stdarg.h
-
va_start
-
va_arg
-
va_end
-
An example of use
See also vprintf vfprintf and vsprintf which
all print the contents of a va_list
stddef.h
-
No functions are declared in stddef.h.
stdio.h
-
This header defines all the ANSI I/O functions that allow you to read and
write to files and devices. Low level (non
ANSI) functions are also available.
-
clearerr
-
fclose Close a file.
-
feof Check for EOF while reading
a file.
-
fflush
-
fgetc Read a character from a file.
-
fgetpos
-
fgets Read a record from a file (safer than
fgetc).
-
fopen Open a file
-
fprintf O/P a line of data to a file.
-
fputc Put a charater into a file.
-
fputs Put a string into a file.
-
fread
-
freopen
-
fscanf
-
fseek
-
fsetpos
-
ftell
-
fwrite
-
getc Get a character from an input stream.
-
getchar Get a character from the keyboard
(STDIN).
-
gets Get string (from keyboard).
-
perror
-
printf O/P data to the screen or a file.
-
putchar O/P a character to STDOUT.
-
puts O/P data to the screen or a file.
-
remove Remove a file.
-
rewind
-
scanf
-
setbuf
-
setvbuf
-
sprintf O/P data in tha same way as 'printf'
but put it into a string.
-
sscanf Extract fields from a string.
-
tmpfile
-
tmpnam
-
ungetc
-
vfprintf O/P a va_list to a file.
-
vprintf O/P a va_list to stdout.
-
vsprintf O/P a va_list to a string.
stdlib.h
-
abort a program.
-
abs compute the absolute value of an
integer. Can be defined outside stdlib.h as macro:
#define abs(amt) ((amt)<0?0-(amt):(amt))
-
atexit Execute the named function when the
program terminates.
-
atof convert a string to a double
-
atoi Accepts +-0123456789
leading blanks and converts to integer.
-
atol convert a string to a long integer
-
bsearch Binary chop.
-
calloc memory for an array.
-
div compute the quotient and remainder
of integer division
-
exit Normally terminate a program.
-
getenv Get an environmental variable.
-
free memory allocated with malloc.
-
labs compute the absolute value of
a long integer
-
ldiv compute the quotient and remainder
of long integer division.
-
malloc dynamically allocate memory.
-
mblen determine the number of bytes
in a character
-
mbstowcs convert a multibyte string
to a wide character string.
-
mbtowc convert a multibyte character
to a wide character
-
qsort Sort an array.
-
rand Generate a random number.
-
realloc Reallocate memory.
-
strtod Convert a string to a double.
-
strtol String to long integer conversion.
Takes data in various number bases.
-
strtoul Convert a string to an unsigned
long. This can also perform number base conversion.
-
srand Seed a random number.
-
system Issue a command to the operating
system
-
wctomb convert a wide character to
a multibyte character.
-
wcstombs convert a wide character
string to a multibyte character string.
string.h
-
memchr Copy a character
into memory.
-
memcmp Compare memory locations.
-
memcpy Copy memory.
-
memmove Move memory.
-
memset Set memory.
-
strcat Concatinate two strings.
-
strchr Search for a character
in a string.
-
strcmp Compare strings.
-
strcoll
-
strcpy Copy strings.
-
strcspn
-
strerror
-
strlen Length of a string.
-
strncat Concatinate two strings.
-
strncmp Compare two strings.
-
strncpy Copy part of a string.
-
strpbrk
-
strrchr Search for a character in a string.
-
strspn
-
strstr Search a string for a substring.
-
strtok The books say this function splits
a string into tokens. I think its function is best described as parsing a
string.
-
strxfrm
time.h
-
asctime
-
clock
-
ctime
-
difftime
-
gmtime
-
localtime
-
mktime
-
strftime
-
time
-
Example program using some of the time
functions.
POSIX functions start here....
-
cpio.h
-
dirent.h
-
opendir Open a directory.
-
closedir Close a directory.
-
readdir Read a directory entry.
-
rewinddir Return to the beginning of
a directory.
-
scandir Scan a directory for a matching
entry.
-
seekdir Move to an offset in a directory.
-
telldir Return the location within a
directory.
fcntl.h
-
grp.h
-
pwd.h
-
sys/stat.h
-
sys/times.h
-
sys/types.h
-
sys/utsname.h
-
sys/wait.h
-
tar.h
-
termios.h
-
unistd.h
-
It seems that this library contains headers for many functions that originally
came with the ANSII standard library but did not have headers. My
documentation for this POSIX library is incomplete.
-
access
-
alarm
-
chdir Change the current working
directory.
-
chown Change the ownership of a file.
-
close Close a file (see
low level functions)
-
chroot Change the root directory
I am not 100% sure this is supposed to be in unistd.
-
ctermid
-
cuserid
-
dup duplicate a file descriptor
-
dup2 duplicate a file descriptor
-
execl
-
execle
-
execlp
-
execv
-
execve
-
execvp
-
fchdir Change the current working
directory.I am not 100% sure this is supposed to be in unistd.
-
fork Create a child process.
-
fpathconf Change the current working
directory.I am not 100% sure this is supposed to be in unistd.
-
getegid Get the group ID of the process.
-
geteuid Get the User ID of the process.
-
gethostname Name of the host
(see uname). Not 100% sure this is in unistd
-
getopt, parse the command line Not
100% sure this is in unistd.
-
getgid Get a group ID.
-
getgroups
-
getlogin
-
getpgrp
-
getpid get process ID.
-
getppid, get parent process ID.
-
getuid Get the User ID of the process.
-
isatty
-
link
-
lseek
-
mkdir Make a directory
-
open Open a file
-
pathconf
-
pause Put the program to sleep.
-
pipe
-
read Read a file descriptor.
-
rename Rename a file. This function
can also be found in the ANSI stdio library. MAN PAGE.
-
rmdir Remove a directory
-
setgid Set the Group ID of the process.
-
setpgid
-
setsid
-
setuid Set the User
ID of the process.
-
sleep Pause for a
required number of seconds.
-
sysconf
-
tcgetpgrp
-
tcsetpgrp
-
ttyname
-
unlink Remove a file
-
write Write to a file descriptor.
utime.h
-
conio.h
-
Dos Specific functions in conio.h Not very portable as conio.h is NOT in
the ANSI standard library and does not appear on the Sun or Linux machines.
-
clrscr Clear screen
-
getch Get a character from the keyboard.
-
getche Get a character from the keyboard.
Non ANSI Standard Unix Functions.
These functions are not in the ANSI standard libraries but are handy all
the same.
-
dirent.h Functions
performing actions on directories
-
statfs Filesystem statistics.
-
unistd.h
-
Ungrouped functions.
Ungrouped functions
-
endpwent
-
fgetpwent
-
getpw Get a password entry.
-
getpwent Get a password entry.
-
getpwnam Get a record by keying on the
user name.
-
getpwuid Get a record by keying on the
UID (numeric).
-
getuidx Get the User ID of a process
(RS/6000 only).
-
index Search for a character in a string
(Use strchr to conform to the ANSI standard).
-
putpwent
-
pclose Close a pipe.
-
popen Open a Unix pipe.
-
putenv Change or create an environmental
variable.
-
setenv Change or create an environmental
variable.
-
setpwent
-
setreuid Set the ID of the process calling
process.
-
stat Get status information on files
(modification time, file size etc).
-
uname Get information
about the machine we are running on.
-
unsetenv Remove an environmental variable.
-
setuidx Set the User ID of the process
(RS/6000 only).
-
setegid setrgid Set the Group ID of
the process.
-
seteuid setruid Set
the User ID of the process.
-
getruid Get the User ID of the process.
-
sizeof Return the storage allocation
for a data type.This is actually
an operator! I have put it in here as it looks like a function and so you
will probably look for it here....
-
example showing the size of data types
-
example showing the size of data objects.
-
User written functions
(and a few lifted from books)
-
clrscr. Clear the
screen using VT escape sequence.
-
convesc. Insert escape codes into a
text string.
-
basename. Strip directory information
from a Unix file name.
-
printenv. List the environmental variables.
-
lenstr User written version of
strlen
-
reverse Reverse characters in a string.
Martin Leslie
18-Feb-96