You are on page 1of 5

Appendix E Common C Functions

This appendix lists the function prototypes contained in each of the header files supplied with most C compilers. Functions that
have an asterisk after them were covered in this book.
The functions are listed alphabetically. Following each name and header file is the complete prototype. Notice that the header
file prototypes use a notation different from that used in this book. For each parameter a function takes, only the type is given
in the prototype; no parameter name is included. Here are two examples:

int func1(int, int *);


int func1(int x, int *y);
Both declarations specify two parameters--the first a type int, and the second a pointer to type int. As far as the compiler is
concerned, these two declarations are equivalent.

Table E.1. Common C functions listed in alphabetical order.


Function Header
File

Function Prototype

abort*
abs

STDLIB.H
STDLIB.H

void abort(void);
int abs(int);

acos*
asctime*
asin*

MATH.H
TIME.H
MATH.H

double acos(double);
char *asctime(const struct tm *);
double asin(double);

assert*
atan*

ASSERT.H void assert(int);


MATH.H
double atan(double);

atan2 *
atexit*
atof*

MATH.H
STDLIB.H
STDLIB.H

double atan2(double, double);


int atexit(void (*)(void));
double atof(const char *);

atof*
atoi*

MATH.H
STDLIB.H

double atof(const char *);


int atoi(const char *);

atol*
bsearch*

STDLIB.H
STDLIB.H

long atol(const char *);


void *bsearch(const void *, const void *, size_t, size_t, int(*) (const void
*, const void *));

calloc*
ceil*

STDLIB.H
MATH.H

void *calloc(size_t, size_t);


double ceil(double);

clearerr
clock*
cos*

STDIO.H
TIME.H
MATH.H

void clearerr(FILE *);


clock_t clock(void);
double cos(double);

cosh*
ctime*

MATH.H
TIME.H

double cosh(double);
char *ctime(const time_t *);

difftime
div
exit*

TIME.H
STDLIB.H
STDLIB.H

double difftime(time_t, time_t);


div_t div(int, int);
void exit(int);

exp*
fabs*

MATH.H
MATH.H

double exp(double);
double fabs(double);
422

fclose*
fcloseall*

STDIO.H
STDIO.H

int fclose(FILE *);


int fcloseall(void);

feof*
fflush*

STDIO.H
STDIO.H

int feof(FILE *);


int fflush(FILE *);

fgetc*
fgetpos
fgets*

STDIO.H
STDIO.H
STDIO.H

int fgetc(FILE *);


int fgetpos(FILE *, fpos_t *);
char *fgets(char *, int, FILE *);

floor*
flushall*

MATH.H
STDIO.H

double floor(double);
int flushall(void);

fmod*
fopen*
fprintf*

MATH.H
STDIO.H
STDIO.H

double fmod(double, double);


FILE *fopen(const char *, const char *);
int fprintf(FILE *, const char *, ...);

fputc*
fputs*

STDIO.H
STDIO.H

int fputc(int, FILE *);


int fputs(const char *, FILE *);

fread*
free*
freopen

STDIO.H
STDLIB.H
STDIO.H

size_t fread(void *, size_t, size_t, FILE *);


void free(void *);
FILE *freopen(const char *, const char *, FILE *);

frexp *
fscanf*

MATH.H
STDIO.H

double frexp(double, int *);


int fscanf(FILE *, const char *, ...);

fseek*
fsetpos
ftell*

STDIO.H
STDIO.H
STDIO.H

int fseek(FILE *, long, int);


int fsetpos(FILE *, const fpos_t *);
long ftell(FILE *);

fwrite *
getc*

STDIO.H
STDIO.H

size_t fwrite(const void *, size_t, size_t, FILE *);


int getc(FILE *);

getch*
getchar*
getche *

STDIO.H
STDIO.H
STDIO.H

int getch(void);
int getchar(void);
int getche(void);

getenv
gets*

STDLIB.H
STDIO.H

char *getenv(const char *);


char *gets(char *);

gmtime
isalnum *
isalpha *

TIME.H
CTYPE.H
CTYPE.H

struct tm *gmtime(const time_t *);


int isalnum(int);
int isalpha(int);

isascii*
iscntrl*

CTYPE.H
CTYPE.H

int isascii(int);
int iscntrl(int);

isdigit*
isgraph*
islower*

CTYPE.H
CTYPE.H
CTYPE.H

int isdigit(int);
int isgraph(int);
int islower(int);

isprint*

CTYPE.H

int isprint(int);
423

ispunct*
isspace*

CTYPE.H
CTYPE.H

int ispunct(int);
int isspace(int);

isupper*
isxdigit*

CTYPE.H
CTYPE.H

int isupper(int);
int isxdigit(int);

labs
ldexp
ldiv

STDLIB.H
MATH.H
STDLIB.H

long int labs(long int);


double ldexp(double, int);
ldiv_t div(long int, long int);

localtime* TIME.H
log*
MATH.H

struct tm *localtime(const time_t *);


double log(double);

log10*
malloc*
mblen

double log10(double);
void *malloc(size_t);
int mblen(const char *, size_t);

MATH.H
STDLIB.H
STDLIB.H

mbstowcs STDLIB.H
mbtowc
STDLIB.H

size_t mbstowcs(wchar_t *, const char *, size_t);


int mbtowc(wchar_t *, const char *, size_t);

memchr
STRING.H
memcmp STRING.H
memcpy STRING.H

void *memchr(const void *, int, size_t);


int memcmp(const void *, const void *, size_t);
void *memcpy(void *, const void *, size_t);

memmove STRING.H
memset
STRING.H

void *memmove(void *, const void*, size_t);


void *memset(void *, int, size_t);

mktime*
modf
perror*

TIME.H
MATH.H
STDIO.H

time_t mktime(struct tm *);


double modf(double, double *);
void perror(const char *);

pow*
printf*

MATH.H
STDIO.H

double pow(double, double);


int printf(const char *, ...);

putc*
putchar*
puts*

STDIO.H
STDIO.H
STDIO.H

int putc(int, FILE *);


int putchar(int);
int puts(const char *);

qsort*
rand

STDLIB.H
STDLIB.H

void qsort(void*, size_t, size_t, int (*)(const void*, const void *));
int rand(void);

realloc*
remove *
rename*

STDLIB.H
STDIO.H
STDIO.H

void *realloc(void *, size_t);


int remove(const char *);
int rename(const char *, const char *);

rewind *
scanf*

STDIO.H
STDIO.H

void rewind(FILE *);


int scanf(const char *, ...);

setbuf
setvbuf
sin*

STDIO.H
STDIO.H
MATH.H

void setbuf(FILE *, char *);


int setvbuf(FILE *, char *, int, size_t);
double sin(double);

sinh*

MATH.H

double sinh(double);
424

sleep*
sprintf

TIME.H
STDIO.H

void sleep(time_t);
int sprintf(char *, const char *, ...);

sqrt*
srand

MATH.H
STDLIB.H

double sqrt(double);
void srand(unsigned);

sscanf
strcat*
strchr *

STDIO.H
STRING.H
STRING.H

int sscanf(const char *, const char *, ...);


char *strcat(char *,const char *);
char *strchr(const char *, int);

strcmp*
strcmpl*

STRING.H
STRING.H

int strcmp(const char *, const char *);


int strcmpl(const char *, const char *);

strcpy*
strcspn*
strdup *

STRING.H
STRING.H
STRING.H

char *strcpy(char *, const char *);


size_t strcspn(const char *, const char *);
char *strdup(const char *);

strerror
strftime*

STRING.H
TIME.H

char *strerror(int);
size_t strftime(char *, size_t, const char *, const struct tm *);

strlen*
strlwr*
strncat*

STRING.H
STRING.H
STRING.H

size_t strlen(const char *);


char *strlwr(char *);
char *strncat(char *, const char *, size_t);

strncmp*
strncpy*

STRING.H
STRING.H

int strncmp(const char *, const char *, size_t);


char *strncpy(char *, const char *, size_t);

strnset*
strpbrk*
strrchr *

STRING.H
STRING.H
STRING.H

char *strnset(char *, int, size_t);


char *strpbrk(const char *, const char *);
char *strrchr(const char *, int);

strspn*
strstr*

STRING.H
STRING.H

size_t strspn(const char *, const char *);


char *strstr(const char *, const char *);

strtod
strtok
strtol

STDLIB.H
STRING.H
STDLIB.H

double strtod(const char *, char **);


char *strtok(char *, const char*);
long strtol(const char *, char **, int);

strtoul
strupr*

STDLIB.H
STRING.H

unsigned long strtoul(const char*, char **, int);


char *strupr(char *);

system*
tan*
tanh*

STDLIB.H
MATH.H
MATH.H

int system(const char *);


double tan(double);
double tanh(double);

time*
tmpfile

TIME.H
STDIO.H

time_t time(time_t *);


FILE *tmpfile(void);

tmpnam*
tolower
toupper

STDIO.H
CTYPE.H
CTYPE.H

char *tmpnam(char *);


int tolower(int);
int toupper(int);

ungetc*

STDIO.H

int ungetc(int, FILE *);


425

va_arg*
va_end *

STDARG.H (type) va_arg(va_list, (type));


STDARG.H void va_end(va_list);

va_start*
vfprintf

STDARG.H void va_start(va_list, lastfix);


STDIO.H
int vfprintf(FILE *, constchar *, ...);

vprintf
STDIO.H
vsprintf
STDIO.H
wcstombs STDLIB.H

int vprintf(FILE*, constchar *, ...);


int vsprintf(char *, constchar *, ...);
size_t wcstombs(char *, const wchar_t *, size_t);

wctomb

int wctomb(char *, wchar_t);

STDLIB.H

426

You might also like