Standard C Library

Standard C Library:
http://www.cppreference.com/
=============================================
    * Standard C I/O
    * Standard C String & Character
    * Standard C Math
    * Standard C Time & Date
    * Standard C Memory
    * Other standard C functions
=============================================
Standard C I/O
clearerr()  clears errors
fclose()  close a file
feof()   true if at the end-of-file
ferror()  checks for a file error
fflush()  writes the contents of the output buffer
fgetc()  get a character from a stream
fgetpos()  get the file position indicator
fgets()  get a string of characters from a stream
fopen()  open a file
fprintf()  print formatted output to a file
fputc()  write a character to a file
fputs()  write a string to a file
fread()  read from a file
freopen()  open an existing stream with a different name
fscanf()  read formatted input from a file
fseek()  move to a specific location in a file
fsetpos()  move to a specific location in a file
ftell()  returns the current file position indicator
fwrite()  write to a file
getc()   read a character from a file
getchar()  read a character from STDIN
gets()   read a string from STDIN
perror()  displays a string version of the current error to STDERR
printf()  write formatted output to STDOUT
putc()   write a character to a stream
putchar()  write a character to STDOUT
puts()   write a string to STDOUT
remove()  erase a file
rename()  rename a file
rewind()  move the file position indicator to the beginning of a file
scanf()  read formatted input from STDIN
setbuf()  set the buffer for a specific stream
setvbuf()  set the buffer and size for a specific stream
sprintf()  write formatted output to a buffer
sscanf()  read formatted input from a buffer
tmpfile()  return a pointer to a temporary file
tmpnam()  return a unique filename
ungetc()  puts a character back into a stream
vprintf, vfprintf, vsprintf  write formatted output with variable argument lists
=============================================
Standard C string and character
atof()   converts a string to a double
atoi()   converts a string to an integer
atol()   converts a string to a long
isalnum()  true if alphanumeric
isalpha()  true if alphabetic
iscntrl()  true if control character
isdigit()  true if digit
isgraph()  true if a graphical character
islower()  true if lowercase
isprint()  true if a printing character
ispunct()  true if punctuation
isspace()  true if space
isupper()  true if uppercase character
isxdigit()  true if a hexidecimal character
memchr()  searches an array for the first occurance of a character
memcmp()  compares two buffers
memcpy()  copies one buffer to another
memmove()  moves one buffer to another
memset()  fills a buffer with a character
strcat()  concatenates two strings
strchr()  finds the first occurance of a character in a string
strcmp()  compares two strings
strcoll()  compares two strings in accordance to the current locale
strcpy()  copies one string to another
strcspn()  searches one string for any characters in another
strerror()  returns a text version of a given error code
strlen()  returns the length of a given string
strncat()  concatenates a certain amount of characters of two strings
strncmp()  compares a certain amount of characters of two strings
strncpy()  copies a certain amount of characters from one string to another
strpbrk()  finds the first location of any character in one string, in another string
strrchr()  finds the last occurance of a character in a string
strspn()  returns the length of a substring of characters of a string
strstr()  finds the first occurance of a substring of characters
strtod()  converts a string to a double
strtok()  finds the next token in a string
strtol()  converts a string to a long
strtoul()  converts a string to an unsigned long
strxfrm()  converts a substring so that it can be used by string comparison functions
tolower()  converts a character to lowercase
toupper()  converts a character to uppercase
=============================================
Standard C Math
abs()  absolute value
acos()  arc cosine
asin()  arc sine
atan()  arc tangent
atan2() arc tangent, using signs to determine quadrants
ceil()  the smallest integer not less than a certain value
cos()  cosine
cosh()  hyperbolic cosine
div()  returns the quotient and remainder of a division
exp()  returns "e" raised to a given power
fabs()  absolute value for floating-point numbers
floor() returns the largest integer not greater than a given value
fmod()  returns the remainder of a division
frexp() decomposes a number into scientific notation
labs()  absolute value for long integers
ldexp() computes a number in scientific notation
ldiv()  returns the quotient and remainder of a division, in long integer form
log()  natural logarithm
log10() natural logarithm, in base 10
modf()  decomposes a number into integer and fractional parts
pow()  returns a given number raised to another number
sin()  sine
sinh()  hyperbolic sine
sqrt()  square root
tan()  tangent
tanh()  hyperbolic tangent
=============================================
Standard C Time & Date
asctime()  a textual version of the time
clock()  returns the amount of time that the program has been running
ctime()  returns a specifically formatted version of the time
difftime()  the difference between two times
gmtime()  returns a pointer to the current Greenwich Mean Time
localtime()  returns a pointer to the current time
mktime()  returns the calendar version of a given time
strftime()  returns individual elements of the date and time
time()   returns the current calendar time of the system
=============================================
Standard C Memory
calloc()  allocates a two-dimensional chunk of memory
free()   makes memory available for future allocation
malloc()  allocates memory
realloc()  changes the size of previously allocated memory
=============================================
Other standard C functions
abort()  stops the program
assert()  stops the program if an expression isn't true
atexit()  sets a function to be called when the program exits
bsearch()  perform a binary search
exit()   stop the program
getenv()  get enviornment information about a variable
longjmp()  start execution at a certain point in the program
qsort()  perform a quicksort
raise()  send a signal to the program
rand()   returns a pseudorandom number
setjmp()  set execution to start at a certain point
signal()  register a function as a signal handler
srand()  initialize the random number generator
system()  perform a system call
va_arg()  use variable length parameter lists

********************************************************************************************
=============================================
Standard C I/O
clearerr
Syntax:

  #include <stdio.h>
  void clearerr( FILE *stream );

The clearerr function resets the error flags and EOF indicator for the given stream. When an error occurs, you can use

perror() to figure out which error actually occurred.
Related topics:
feof(), ferror(), and perror().
fclose
Syntax:

  #include <stdio.h>
  int fclose( FILE *stream );

The function fclose() closes the given file stream, deallocating any buffers associated with that stream. fclose() returns 0

upon success, and EOF otherwise.
Related topics:
fopen(), freopen(), fflush()
feof
Syntax:

  #include <stdio.h>
  int feof( FILE *stream );

The function feof() returns a nonzero value if the end of the given file stream has been reached.
Related topics:
clearerr(), ferror(), perror(), putc(), getc()
ferror
Syntax:

  #include <stdio.h>
  int ferror( FILE *stream );

The ferror() function looks for errors with stream, returning zero if no errors have occured, and non-zero if there is an

error. In case of an error, use perror() to determine which error has occured.
Related topics:
clearerr(), feof(), perror()
fflush
Syntax:

  #include <stdio.h>
  int fflush( FILE *stream );

If the given file stream is an output stream, then fflush() causes the output buffer to be written to the file. If the given

stream is of the input type, then fflush() causes the input buffer to be cleared. fflush() is useful when debugging, if a

program segfaults before it has a chance to write output to the screen. Calling fflush( STDOUT ) directly after debugging

output will ensure that your output is displayed at the correct time.

    printf( "Before first call/n" );
    fflush( STDOUT );
    shady_function();
    printf( "Before second call/n" );
    fflush( STDOUT );
    dangerous_dereference();

Related topics:
fclose(), fopen(), fread(), fwrite(), getc(), putc()
fgetc
Syntax:

  #include <stdio.h>
  int fgetc( FILE *stream );

The fgetc() function returns the next character from stream, or EOF if the end of file is reached or if there is an error.
Related topics:
fputc(), getc(), putc(), fopen()
fgetpos
Syntax:

  #include <stdio.h>
  int fgetpos( FILE *stream, fpos_t *position );

The fgetpos() function stores the file position indicator of the given file stream in the given position variable. The

position variable is of type fpos_t (which is defined in stdio.h) and is an object that can hold every possible position in a

FILE. fgetpos() returns zero upon success, and a non-zero value upon failure.
Related topics:
fsetpos(), fseek(), ftell()
fgets
Syntax:

  #include <stdio.h>
  char *fgets( char *str, int num, FILE *stream );

The function fgets() reads up to num - 1 characters from the given file stream and dumps them into str. fgets() will stop

when it reaches the end of a line, in which case str will be terminated with a newline. If fgets() reaches num - 1 characters

or encounters the EOF, str will be null-terminated. fgets() returns str on success, and NULL on an error.
fopen
Syntax:

  #include <stdio.h>
  FILE *fopen( const char *fname, const char *mode );

The fopen() function opens a file indicated by fname and returns a stream associated with that file. If there is an error,

fopen() returns NULL. mode is used to determine how the file will be treated (i.e. for input, output, etc)
Mode  Meaning
"r"  Open a text file for reading
"w"  Create a text file for writing
"a"  Append to a text file
"rb"  Open a binary file for reading
"wb"  Create a binary file for writing
"ab"  Append to a binary file
"r+"  Open a text file for read/write
"w+"  Create a text file for read/write
"a+"  Open a text file for read/write
"rb+"  Open a binary file for read/write
"wb+"  Create a binary file for read/write
"ab+"  Open a binary file for read/write

An example:

    char ch;
    FILE *input = fopen( "stuff", "r" );
    ch = getc( input );
   

fprintf
Syntax:

  #include <stdio.h>
  int fprintf( FILE *stream, const char *format, ... );

The fprintf() function sends information (the arguments) according to the specified format to the file indicated by stream.

fprintf() works just like printf() as far as the format goes. The return value of fprintf() is the number of characters

outputted, or a negative number if an error occurs. An example:

    char name[20] = "Mary";
    FILE *out;
    out = fopen( "output.txt", "w" );
    if( out != NULL )
      fprintf( out, "Hello %s/n", name );

Related topics:
printf(), fscanf()
fputc
Syntax:

  #include <stdio.h>
  int fputc( int ch, FILE *stream );

The function fputc() writes the given character ch to the given output stream. The return value is the character, unless

there is an error, in which case the return value is EOF.
Related topics:
fgetc(), fopen(), fprintf(), fread(), fwrite()
fputs
Syntax:

  #include <stdio.h>
  int fputs( const char *str, FILE *stream );

The fputs() function writes an array of characters pointed to by str to the given output stream. The return value is

non-negative on success, and EOF on failure.
Related topics:
fgets(), gets(), puts(), fprintf(), fscanf()
fread
Syntax:

  #include <stdio.h>
  int fread( void *buffer, size_t size, size_t num, FILE *stream );

The function fread() reads num number of objects (where each object is size bytes) and places them into the array pointed to

by buffer. The data comes from the given input stream. The return value of the function is the number of things read...use

feof() or ferror() to figure out if an error occurs.
Related topics:
fwrite(), fopen(), fscanf(), fgetc(), getc()
freopen
Syntax:

  #include <stdio.h>
  FILE *freopen( const char *fname, const char *mode, FILE *stream );

The freopen() function is used to reassign an existing stream to a different file and mode. After a call to this function,

the given file stream will refer to fname with access given by mode. The return value of freopen() is the new stream, or NULL

if there is an error.
Related topics:
fopen(), fclose()
fscanf
Syntax:

  #include <stdio.h>
  int fscanf( FILE *stream, const char *format, ... );

The function fscanf() reads data from the given file stream in a manner exactly like scanf(). The return value of fscanf() is

the number of variables that are actually assigned values, or EOF if no assignments could be made.
Related topics:
scanf(), fprintf()
fseek
Syntax:

  #include <stdio.h>
  int fseek( FILE *stream, long offset, int origin );

The function fseek() sets the file position data for the given stream. The origin value should have one of the following

values (defined in stdio.h):
Name  Explanation
SEEK_SET  Seek from the start of the file
SEEK_CUR  Seek from the current location
SEEK_END  Seek from the end of the file

fseek() returns zero upon success, non-zero on failure. You can use fseek() to move beyond a file, but not before the

beginning. Using fseek() clears the EOF flag associated with that stream.
Related topics:
ftell(), rewind(), fopen(), fgetpos(), fsetpos()
fsetpos
Syntax:

  #include <stdio.h>
  int fsetpos( FILE *stream, const fpos_t *position );

The fsetpos() function moves the file position indicator for the given stream to a location specified by the position object.

fpos_t is defined in stdio.h. The return value for fsetpos() is zero upon success, non-zero on failure.
Related topics:
fgetpos(), fseek(), ftell()
ftell
Syntax:

  #include <stdio.h>
  long ftell( FILE *stream );

The ftell() function returns the current file position for stream, or -1 if an error occurs.
Related topics:
fseek(), fgetpos()
fwrite
Syntax:

  #include <stdio.h>
  int fwrite( const void *buffer, size_t size, size_t count, FILE *stream );

The fwrite() function writes, from the array buffer, count objects of size size to stream. The return value is the number of

objects written.
Related topics:
fread(), fscanf(), getc(), fgetc()
getc
Syntax:

  #include <stdio.h>
  int getc( FILE *stream );

The getc() function returns the next character from stream, or EOF if the end of file is reached. getc() is identical to

fgetc(). For example:

    char ch;
    FILE *input = fopen( "stuff", "r" );
   
    ch = getc( input );
    while( ch != EOF ) {
      printf( "%c", ch );
      ch = getc( input );
    }

Related topics:
fputc(), fgetc(), putc(), fopen()
getchar
Syntax:

  #include <stdio.h>
  int getchar( void );

The getchar() function returns the next character from STDIN, or EOF if the end of file is reached.
Related topics:
fputc(), fgetc(), putc(), fopen()
gets
Syntax:

  #include <stdio.h>
  char *gets( char *str );

The gets() function reads characters from STDIN and loads them into str, until a newline or EOF is reached. The newline

character is translated into a null termination. The return value of gets() is the read-in string, or NULL if there is an

error.
Related topics:
fputs(), fgetc(), fgets(), puts()
perror
Syntax:

  #include <stdio.h>
  void perror( const char *str );

The perror() function prints str and an implementation-defined error message corresponding to the global variable errno.
printf
Syntax:

  #include <stdio.h>
  int printf( const char *format, ... );

The printf() function prints output to STDOUT, according to format and other arguments passed to printf(). The string format

consists of two types of items - characters that will be printed to the screen, and format commands that define how the other

arguments to printf() are displayed. Basically, you specify a format string that has text in it, as well as "special"

characters that map to the other arguments of printf(). For example, this code

    char name[20] = "Bob";
    int age = 21;
    printf( "Hello %s, you are %d years old/n", name, age );

displays the following output:

    Hello Bob, you are 21 years old

The %s means, "insert the first argument, a string, right here." The %d indicates that the second argument (an integer)

should be placed there. There are different %-codes for different variable types, as well as options to limit the length of

the variables and whatnot.
Code  Format
%c  character
%d  signed integers
%i  signed integers
%e  scientific notation, with a lowercase "e"
%E  scientific notation, with a uppercase "E"
%f  floating point
%g  use %e or %f, whichever is shorter
%G  use %E or %f, whichever is shorter
%o  octal
%s  a string of characters
%u  unsigned integer
%x  unsigned hexadecimal, with lowercase letters
%X  unsigned hexadecimal, with uppercase letters
%p  a pointer
%n  the argument shall be a pointer to an integer
into which is placed the number of characters
written so far
%%  a '%' sign

An integer placed between a % sign and the format command acts as a minimum field width specifier, and pads the output with

spaces or zeros to make it long enough. If you want to pad with zeros, place a zero before the minimum field width specifier.

You can use a precision modifier, which has different meanings depending on the format code being used.

    * With %e, %E, and %f, the precision modifier lets you specify the number of decimal places desired. For example,

    %12.6f

      will display a floating number at least 12 digits wide, with six decimal places.
    * With %g and %G, the precision modifier determines the maximum number of significant digits displayed.
    * With %s, the precision modifer simply acts as a maximumfield length, to complement the minimum field length that

precedes the period.

All of printf()'s output is right-justified, unless you place a minus sign right after the % sign. For example,

    %-12.4f

will display a floating point number with a minimum of 12 characters, 4 decimal places, and left justified. You may modify

the %d, %i, %o, %u, and %x type specifiers with the letter l and the letter h to specify long and short data types (e.g. %hd

means a short integer). The %e, %f, and %g type specifiers can have the letter l before them to indicate that a double

follows. The %g, %f, and %e type specifiers can be preceded with the character '#' to ensure that the decimal point will be

present, even if there are no decimal digits. The use of the '#' character with the %x type specifier indicates that the

hexidecimal number should be printed with the '0x' prefix. The use of the '#' character with the %o type specifier indicates

that the octal value should be displayed with a 0 prefix.

You can also include constant escape sequences in the output string.

The return value of printf() is the number of characters printed, or a negative number if an error occurred.
Related topics:
scanf(), fprintf()
putc
Syntax:

  #include <stdio.h>
  int putc( int ch, FILE *stream );

The putc() function writes the character ch to stream. The return value is the character written, or EOF if there is an

error. For example:

    char ch;
    FILE *input, *output;
    input = fopen( "tmp.c", "r" );
    output = fopen( "tmpCopy.c", "w" );
    ch = getc( input );
    while( ch != EOF ) {
      putc( ch, output );
      ch = getc( input );
    }
    fclose( input );
    fclose( output );

generates a copy of the file tmp.c called tmpCopy.c.
Related topics:
fgetc(), fputc(), getchar(), putchar()
putchar
Syntax:

  #include <stdio.h>
  int putchar( int ch );

The putchar() function writes ch to STDOUT. The code

    putchar( ch );

is the same as

    putc( ch, STDOUT );

The return value of putchar() is the written character, or EOF if there is an error.
Related topics:
putc()
puts
Syntax:

  #include <stdio.h>
  int puts( char *str );

The function puts() writes str to STDOUT. puts() returns non-negative on success, or EOF on failure.
Related topics:
putc(), gets(), printf()
remove
Syntax:

  #include <stdio.h>
  int remove( const char *fname );

The remove() function erases the file specified by fname. The return value of remove() is zero upon success, and non-zero if

there is an error.
Related topics:
rename()
rename
Syntax:

  #include <stdio.h>
  int rename( const char *oldfname, const char *newfname );

The function rename() changes the name of the file oldfname to newfname. The return value of rename() is zero upon success,

non-zero on error.
Related topics:
remove()
rewind
Syntax:

  #include <stdio.h>
  void rewind( FILE *stream );

The function rewind() moves the file position indicator to the beginning of the specified stream, also clearing the error and

EOF flags associated with that stream.
Related topics:
fseek()
scanf
Syntax:

  #include <stdio.h>
  int scanf( const char *format, ... );

The scanf() function reads input from stdin, according to the given format, and stores the data in the other arguments. It

works a lot like printf(). The format string consists of control characters, whitespace characters, and non-whitespace

characters. The control characters are preceded by a % sign, and are as follows:
Control Character  Explanation
%c  a single character
%d  a decimal integer
%i  an integer
%e, %f, %g  a floating-point number
%o  an octal number
%s  a string
%x  a hexadecimal number
%p  a pointer
%n  an integer equal to the number of characters read so far
%u  an unsigned integer
%[]  a set of characters
%%  a percent sign

scanf() reads the input, matching the characters from format. When a control character is read, it puts the value in the next

variable. Whitespace (tabs, spaces, etc) are skipped. Non-whitespace characters are matched to the input, then discarded. If

a number comes between the % sign and the control character, then only that many characters will be converted into the

variable. If scanf() encounters a set of characters, denoted by the %[] control character, then any characters found within

the brackets are read into the variable. The return value of scanf() is the number of variables that were successfully

assigned values, or EOF if there is an error.
Related topics:
printf() and fscanf().
setbuf
Syntax:

  #include <stdio.h>
  void setbuf( FILE *stream, char *buffer );

The setbuf() function sets stream to use buffer, or, if buffer is null, turns off buffering. If a non-standard buffer size is

used, it should by BUFSIZ characters long.
Related topics:
fopen(), fclose(), setvbuf(),
setvbuf
Syntax:

  #include <stdio.h>
  int setvbuf( FILE *stream, char *buffer, int mode, size_t size );

The function setvbuf() sets the buffer for stream to be buffer, with a size of size. mode can be:

    * _IOFBF, which indicates full buffering
    * _IOLBF, which means line buffering
    * _IONBF, which means no buffering

 

Related topics:
setbuf(),
sprintf
Syntax:

  #include <stdio.h>
  int sprintf( char *buffer, const char *format, ... );

The sprintf() function is just like printf(), except that the output is sent to buffer. The return value is the number of

characters written. For example:

    char string[50];
    int file_number = 0;
   
    sprintf( string, "file.%d", file_number );
    file_number++;
    output_file = fopen( string, "w" );

Related topics:
printf(), fsprintf(),
sscanf
Syntax:

  #include <stdio.h>
  int sscanf( const char *buffer, const char *format, ... );

The function sscanf() is just like scanf(), except that the input is read from buffer.
Related topics:
scanf(), fscanf(),
tmpfile
Syntax:

  #include <stdio.h>
  FILE *tmpfile( void );

The function tempfile() opens a temporary file with an unique filename and returns a pointer to that file. If there is an

error, null is returned.
Related topics:
tmpnam(),
tmpnam
Syntax:

  #include <stdio.h>
  char *tmpnam( char *name );

The tmpnam() function creates an unique filename and stores it in name. tmpnam() can be called up to TMP_MAX times.
Related topics:
tmpfile(),
ungetc
Syntax:

  #include <stdio.h>
  int ungetc( int ch, FILE *stream );

The function ungetc() puts the character ch back in stream.
Related topics:
getc(),
vprintf, vfprintf, and vsprintf
Syntax:

  #include <stdarg.h>
  #include <stdio.h>
  int vprintf( char *format, va_list arg_ptr );
  int vfprintf( FILE *stream, const char *format, va_list arg_ptr );
  int vsprintf( char *buffer, char *format, va_list arg_ptr );

These functions are very much like printf(), fprintf(), and sprintf(). The difference is that the argument list is a pointer

to a list of arguments. va_list is defined in STDARG.H, and is also used by va_arg(). For example:

    void error( char *fmt, ... ) {
      va_list args;
     
      va_start( args, fmt );
      fprintf( stderr, "Error: " );
      vfprintf( stderr, fmt, args );
      fprintf( stderr, "/n" );
      va_end( args );
      exit( 1 );
    }

=============================================
Standard C String & Character
atof
Syntax:

  #include <stdlib.h>
  double atof( const char *str );

The function atof() converts str into a double, then returns that value. str must start with a valid number, but can be

terminated with any non-numerical character, other than "E" or "e". For example,

    x = atof( "42.0is_the_answer" );

results in x being set to 42.0.
Related topics:
atoi() and atol().
atoi
Syntax:

  #include <stdlib.h>
  int atoi( const char *str );

The atoi() function converts str into an integer, and returns that integer. str should start with some sort of number, and

atoi() will stop reading from str as soon as a non-numerical character has been read. For example,

    i = atoi( "512.035" );

would result in i being set to 512.
Related topics:
atof() and atol().
atol
Syntax:

  #include <stdlib.h>
  long atol( const char *str );

The function atol() converts str into a long, then returns that value. atol() will read from str until it finds any character

that should not be in a long. The resulting truncated value is then converted and returned. For example,

    x = atol( "1024.0001" );

results in x being set to 1024L.
Related topics:
atof() and atoi().
isalnum
Syntax:

  #include <ctype.h>
  int isalnum( int ch );

The function isalnum() returns non-zero if its argument is a numeric digit or a letter of the alphabet. Otherwise, zero is

returned.

    char c;
    scanf( "%c", &c );
    if( isalnum(c) )
      printf( "You entered the alphanumeric character %c/n", c );

Related topics:
isalpha(), iscntrl(), isdigit(), isgraph(), isprint(), ispunct(), and isspace().
isalpha
Syntax:

  #include <ctype.h>
  int isalpha( int ch );

The function isalpha() returns non-zero if its argument is a letter of the alphabet. Otherwise, zero is returned.

    char c;
    scanf( "%c", &c );
    if( isalpha(c) )
      printf( "You entered a letter of the alphabet/n" );

Related topics:
isalnum(), iscntrl(), isdigit(), isgraph(), isprint(), ispunct(), and isspace().
iscntrl
Syntax:

  #include <ctype.h>
  int iscntrl( int ch );

The iscntrl() function returns non-zero if its argument is a control character (between 0 and 0x1F or equal to 0x7F).

Otherwise, zero is returned.
Related topics:
isalnum(), isalpha(), isdigit(), isgraph(), isprint(), ispunct(), and isspace().
isdigit
Syntax:

  #include <ctype.h>
  int isdigit( int ch );

The function isdigit() returns non-zero if its argument is a digit between 0 and 9. Otherwise, zero is returned.

    char c;
    scanf( "%c", &c );
    if( isdigit(c) )
      printf( "You entered the digit %c/n", c );

Related topics:
isalnum(), isalpha(), iscntrl(), isgraph(), isprint(), ispunct(), and isspace().
isgraph
Syntax:

  #include <ctype.h>
  int isgraph( int ch );

The function isgraph() returns non-zero if its argument is any printable character other than a space (if you can see the

character, then isgraph() will return a non-zero value). Otherwise, zero is returned.
Related topics:
isalnum(), isalpha(), iscntrl(), isdigit(), isprint(), ispunct(), and isspace().
islower
Syntax:

  #include <ctype.h>
  int islower( int ch );

The islower() function returns non-zero if its argument is a lowercase letter. Otherwise, zero is returned.
Related topics:
isupper()
isprint
Syntax:

  #include <ctype.h>
  int isprint( int ch );

The function isprint() returns non-zero if its argument is a printable character (including a space). Otherwise, zero is

returned.
Related topics:
isalnum(), isalpha(), iscntrl(), isdigit(), isgraph(), ispunct(), and isspace().
ispunct
Syntax:

  #include <ctype.h>
  int ispunct( int ch );

The ispunct() function returns non-zero if its argument is a printing character but neither alphanumeric nor a space.

Otherwise, zero is returned.
Related topics:
isalnum(), isalpha(), iscntrl(), isdigit(), isgraph(), isprint(), and isspace().
isspace
Syntax:

  #include <ctype.h>
  int isspace( int ch );

The isspace() function returns non-zero if its argument is some sort of space (i.e. single space, tab, vertical tab, form

feed, carriage return, or newline). Otherwise, zero is returned.
Related topics:
isalnum(), isalpha(), iscntrl(), isdigit(), isgraph(), and ispunct().
isupper
Syntax:

  #include <ctype.h>
  int isupper( int ch );

The isupper() function returns non-zero if its argument is an uppercase letter. Otherwise, zero is returned.
Related topics:
tolower()
isxdigit
Syntax:

  #include <ctype.h>
  int isxdigit( int ch );

The function isxdigit() returns non-zero if its argument is a hexidecimal digit (i.e. A-F, a-f, or 0-9). Otherwise, zero is

returned.
Related topics:
isalnum(), isalpha(), iscntrl(), isdigit(), isgraph(), ispunct(), and isspace().
memchr
Syntax:

  #include <string.h>
  void *memchr( const void *buffer, int ch, size_t count );

The memchr() function looks for the first occurrence of ch within count characters in the array pointed to by buffer. The

return value points to the location of the first occurrence of ch, or NULL if ch isn't found. For example:

    char names[] = "Alan Bob Chris X Dave";
    if( memchr(names,'X',strlen(names)) == NULL )
      printf( "Didn't find an X/n" );
    else
      printf( "Found an X/n" );

Related topics:
memcpy() and strstr().
memcmp
Syntax:

  #include <string.h>
  int memcmp( const void *buffer1, const void *buffer2, size_t count );

The function memcmp() compares the first count characters of buffer1 and buffer2. The return values are as follows:
Value  Explanation
less than 0  buffer1 is less than buffer2
equal to 0  buffer1 is equal to buffer2
greater than 0  buffer1 is greater than buffer2

Related topics:
memchr(), memcpy(), and strcmp().
memcpy
Syntax:

  #include <string.h>
  void *memcpy( void *to, const void *from, size_t count );

The function memcpy() copies count characters from the array from to the array to. memcpy() returns to. The behavior of

memcpy() is undefined if to and from overlap.
Related topics:
memmove().
memmove
Syntax:

  #include <string.h>
  void *memmove( void *to, const void *from, size_t count );

The memmove() function is identical to memcpy(), except that it works even if to and from overlap.
Related topics:
memcpy().
memset
Syntax:

  #include <string.h>
  void *memset( void *buffer, int ch, size_t count );

The function memset() copies ch into the first count characters of buffer, and returns buffer. memset() is useful for

intializing a section of memory to some value. For example, this command:

    memset( the_array, '/0', sizeof(the_array) );

is a very efficient way to set all values of the_array to zero.
Related topics:
memcmp(), memcpy(), and memmove().
strcat
Syntax:

  #include <string.h>
  char *strcat( char *str1, const char *str2 );

The strcat() function concatenates str2 onto the end of str1, and returns str1. For example:

    printf( "Enter your name: " );
    scanf( "%s", name );
    title = strcat( name, " the Great" );
    printf( "Hello, %s/n", title );

Related topics:
strchr(), strcmp(), and strcpy().
strchr
Syntax:

  #include <string.h>
  char *strchr( const char *str, int ch );

The function strchr() returns a pointer to the first occurence of ch in str, or NULL if ch is not found.
Related topics:
strpbrk(), strspn(), strstr(), and strtok().
strcmp
Syntax:

  #include <string.h>
  int strcmp( const char *str1, const char *str2 );

The function strcmp() compares str1 and str2, then returns:
Return value  Explanation
less than 0  str1 is less than str2
equal to 0  str1 is equal to str2
greater than 0  str1 is greater than str2

For example:

    printf( "Enter your name: " );
    scanf( "%s", name );
    if( strcmp( name, "Mary" ) == 0 )
      printf( "Hello, Dr. Mary!/n" );

Related topics:
memcmp(), strchr(), strcpy(), and strncmp().
strcoll
Syntax:

  #include <string.h>
  int strcoll( const char *str1, const char *str2 );

The strcoll() function compares str1 and str2, much like strcmp. However, strcoll() performs the comparison using the locale

specified by the setlocale() function.
strcpy
Syntax:

  #include <string.h>
  char *strcpy( char *to, const char *from );

The strcpy() function copies characters in the string from to the string to, including the null termination. The return value

is to.
Related topics:
memcpy(), strchr(), strcmp(), strncmp(), and strncpy().
strcspn
Syntax:

  #include <string.h>
  size_t strcspn( const char *str1, const char *str2 );

The function strcspn() returns the index of the first character in str1 that matches any of the characters in str2.
Related topics:
strrchr(), strpbrk(), strstr(), and strtok().
strerror
Syntax:

  #include <string.h>
  char *strerror( int num );

The function strerror() returns an "implementation defined string corresponding to num."
strlen
Syntax:

  #include <string.h>
  size_t strlen( char *str );

The strlen() function returns the length of str (determined by the number of characters before null termination).
Related topics:
memcpy(), strchr(), strcmp(), and strncmp().
strncat
Syntax:

  #include <string.h>
  char *strncat( char *str1, const char *str2, size_t count );

The function strncat() concatenates at most count characters of str2 onto str1, adding a null termination. The resulting

string is returned.
Related topics:
strcat(), strnchr(), strncmp(), and strncpy().
strncmp
Syntax:

  #include <string.h>
  int strncmp( const char *str1, const char *str2, size_t count );

The strncmp() function compares at most count characters of str1 and str2. The return value is as follows:
Return value  Explanation
less than 0  str1 is less than str2
equal to 0  str1 is equal to str2
greater than 0  str1 is greater than str2

If there are less than count characters in either string, then the comparison will stop after the first null termination is

encountered.
Related topics:
strcmp(), strnchr(), and strncpy().
strncpy
Syntax:

  #include <string.h>
  char *strncpy( char *to, const char *from, size_t count );

The strncpy() function copies at most count characters of from to the string to. If from has less than count characters, the

remainder is padded with '/0' characters. The return value is the resulting string.
Related topics:
memcpy(), strchr(), strncat(), and strncmp().
strpbrk
Syntax:

  #include <string.h>
  char *strpbrk( const char *str1, const char *str2 );

The function strpbrk() returns a pointer to the first ocurrence in str1 of any character in str2, or NULL if none are

present.
Related topics:
strspn(), strrchr(), strstr(), and strtok().
strrchr
Syntax:

  #include <string.h>
  char *strrchr( const char *str, int ch );

The function strrchr() returns a pointer to the last occurrence of ch in str, or NULL if no match is found.
Related topics:
strpbrk(), strspn(), strstr(), strtok(),
strspn
Syntax:

  #include <string.h>
  size_t strspn( const char *str1, const char *str2 );

The strspn() function returns the index of the first character in str1 that doesn't match any character in str2.
Related topics:
strpbrk(), strrchr(), strstr(), strtok(),
strstr
Syntax:

  #include <string.h>
  char *strstr( const char *str1, const char *str2 );

The function strstr() returns a pointer to the first occurrence of str2 in str1, or NULL if no match is found.
Related topics:
strchr(), strcspn(), strpbrk(), strspn(), strtok(), strrchr(),
strtod
Syntax:

  #include <stdlib.h>
  double strtod( const char *start, char **end );

The function strtod() returns whatever it encounters first in start as a double. end is set to point at whatever is left in

start after that double. If overflow occurs, strtod() returns either HUGE_VAL or -HUGE_VAL.
Related topics:
atof()
strtok
Syntax:

  #include <string.h>
  char *strtok( char *str1, const char *str2 );

The strtok() function returns a pointer to the next "token" in str1, where str2 contains the delimiters that determine the

token. strtok() returns NULL if no token is found. In order to convert a string to tokens, the first call to strtok() should

have str1 point to the string to be tokenized. All calls after this should have str1 be NULL.

For example:

    char str[] = "now # is the time for all # good men to come to the # aid of their country";
    char delims[] = "#";
    char *result = NULL;
    result = strtok( str, delims );
    while( result != NULL ) {
        printf( "result is /"%s/"/n", result );
        result = strtok( NULL, delims );
    }

The above code will display the following output:

    result is "now "
    result is " is the time for all "
    result is " good men to come to the "
    result is " aid of their country"

Related topics:
strchr(), strcspn(), strpbrk(), strrchr(), and strspn().
strtol
Syntax:

  #include <stdlib.h>
  long strtol( const char *start, char **end, int base );

The strtol() function returns whatever it encounters first in start as a long, doing the conversion to base if necessary. end

is set to point to whatever is left in start after the long. If the result can not be represented by a long, then strtol()

returns either LONG_MAX or LONG_MIN. Zero is returned upon error.
Related topics:
atol().
strtoul
Syntax:

  #include <stdlib.h>
  unsigned long strtoul( const char *start, char **end, int base );

The function strtoul() behaves exactly like strtol(), except that it returns an unsigned long rather than a mere long.
Related topics:
strtol()
strxfrm
Syntax:

  #include <string.h>
  size_t strxfrm( char *str1, const char *str2, size_t num );

The strxfrm() function manipulates the first num characters of str2 and stores them in str1. The result is such that if a

strcoll() is performed on str1 and the old str2, you will get the same result as with a strcmp().
Related topics:
strcmp(), strcoll(),
tolower
Syntax:

  #include <ctype.h>
  int tolower( int ch );

The function tolower() returns the lowercase version of the character ch.
Related topics:
toupper(),
toupper
Syntax:

  #include <ctype.h>
  int toupper( int ch );

The toupper() function returns the uppercase version of the character ch.
Related topics:
tolower(),
=============================================
abs
Syntax:

  #include <stdlib.h>
  int abs( int num );

The abs() function returns the absolute value of num. For example:

    int magic_number = 10;
    cout << "Enter a guess: ";
    cin >> x;
    cout << "Your guess was " << abs( magic_number - x ) << " away from the magic number." << endl;

Related topics:
labs().
acos
Syntax:

  #include <math.h>
  double acos( double arg );

The acos() function returns the arc cosine of arg. arg should be between -1 and 1.
Related topics:
asin(), atan(), atan2(), sin(), cos(), tan(), sinh(), cosh(), and tanh().
asin
Syntax:

  #include <math.h>
  double asin( double arg );

The asin() function returns the arc sine of arg. arg should be between -1 and 1.
Related topics:
acos(), atan(), atan2(), sin(), cos(), tan(), sinh(), cosh(), and tanh().
atan
Syntax:

  #include <math.h>
  double atan( double arg );

The function atan() returns the arc tangent of arg.
Related topics:
asin(), acos(), atan2(), sin(), cos(), tan(), sinh(), cosh(), and tanh().
atan2
Syntax:

  #include <math.h>
  double atan2( double y, double x );

The atan2() function computes the arc tangent of y/x, using the signs of the arguments to compute the quadrant of the return

value.
Related topics:
asin(), acos(), atan(), sin(), cos(), tan(), sinh(), cosh(), and tanh().
ceil
Syntax:

  #include <math.h>
  double ceil( double num );

The ceil() function returns the smallest integer no less than num. For example,

    y = 6.04;
    x = ceil( y );

would set x to 7.0.
Related topics:
floor() and fmod().
cos
Syntax:

  #include <math.h>
  double cos( double arg );

The cos() function returns the cosine of arg, where arg is expressed in radians.
Related topics:
asin(), acos(), atan(), sin(), atan2(), tan(), sinh(), cosh(), and tanh().
cosh
Syntax:

  #include <math.h>
  double cosh( double arg );

The function cosh() returns the hyperbolic cosine of arg.
Related topics:
asin(), acos(), atan(), sin(), atan2(), tan(), sinh(), cos(), and tanh().
div
Syntax:

  #include <stdlib.h>
  div_t div( int numerator, int denominator );

The function div() returns the quotient and remainder of the operation numerator / denominator. The div_t structure is

defined in stdlib.h, and has at least:

    int quot;   // The quotient
    int rem;    // The remainder

For example, the following code displays the quotient and remainder of x/y:

    div_t temp;
    temp = div( x, y );
    printf( "%d divided by %d yields %d with a remainder of %d/n", x, y, temp.quot, temp.rem );

Related topics:
ldiv().
exp
Syntax:

  #include <math.h>
  double exp( double arg );

The exp() function returns e (2.7182818) raised to the argth power.
Related topics:
log().
fabs
Syntax:

  #include <math.h>
  double fabs( double arg );

The function fabs() returns the absolute value of arg.
Related topics:
abs().
floor
Syntax:

  #include <math.h>
  double floor( double arg );

The function floor() returns the largest integer not greater than arg. For example,

    y = 6.04;
    x = floor( y );

would result in x being set to 6.0.
Related topics:
ceil().
fmod
Syntax:

  #include <math.h>
  double fmod( double x, double y );

The fmod() function returns the remainder of x/y.
Related topics:
ceil(), floor(), and fabs().
frexp
Syntax:

  #include <math.h>
  double frexp( double num, int *exp );

The function frexp() is used to decompose num into two parts: a mantissa between 0.5 and 1 (returned by the function) and an

exponent returned as exp. Scientific notation works like this:

    num = mantissa * (2 ^ exp)

Related topics:
ldexp().
labs
Syntax:

  #include <stdlib.h>
  long labs( long num );

The function labs() returns the absolute value of num.
Related topics:
abs().
ldexp
Syntax:

  #include <math.h>
  double ldexp( double num, int exp );

The ldexp() function returns num * (2 ^ exp). And get this: if an overflow occurs, HUGE_VAL is returned.
Related topics:
frexp() and modf().
ldiv
Syntax:

  #include <stdlib.h>
  ldiv_t ldiv( long numerator, long denominator );

The ldiv() function returns the quotient and remainder of the operation numerator / denominator. The ldiv_t structure is

defined in stdlib.h and has at least:

    long quot;  // the quotient
    long rem;   // the remainder

Related topics:
div().
log
Syntax:

  #include <math.h>
  double log( double num );

The function log() returns the natural logarithm of num. There's a domain error if num is negative, a range error if num is

zero.
Related topics:
log10().
log10
Syntax:

  #include <math.h>
  double log10( double num );

The log10() function returns the base 10 logarithm for num. There's a domain error if num is negative, a range error if num

is zero.
Related topics:
log().
modf
Syntax:

  #include <math.h>
  double modf( double num, double *i );

The function modf() splits num into its integer and fraction parts. It returns the fractional part and loads the integer part

into i.
Related topics:
frexp() and ldexp().
pow
Syntax:

  #include <math.h>
  double pow( double base, double exp );

The pow() function returns base raised to the exp power. There's a domain error if base is zero and exp is less than or equal

to zero. There's also a domain error if base is negative and exp is not an integer. There's a range error if there's an

overflow.
Related topics:
exp(), log(), and sqrt().
sin
Syntax:

  #include <math.h>
  double sin( double arg );

The function sin() returns the sine of arg, where arg is given in radians.
Related topics:
asin(), acos(), atan(), cosh(), atan2(), tan(), sinh(), cos(), and tanh().
sinh
Syntax:

  #include <math.h>
  double sinh( double arg );

The function sinh() returns the hyperbolic sine of arg.
Related topics:
asin(), acos(), atan(), cosh(), atan2(), tan(), sin(), cos(), and tanh().
sqrt
Syntax:

  #include <math.h>
  double sqrt( double num );

The sqrt() function returns the square root of num. If num is negative, a domain error occurs.
Related topics:
exp(), log(), and pow().
tan
Syntax:

  #include <math.h>
  double tan( double arg );

The tan() function returns the tangent of arg, where arg is given in radians.
Related topics:
asin(), acos(), atan(), cosh(), atan2(), sinh(), sin(), cos(), and tanh().
tanh
Syntax:

  #include <math.h>
  double tanh( double arg );

The function tanh() returns the hyperbolic tangent of arg.
Related topics:
asin(), acos(), atan(), cosh(), atan2(), tan(), sin(), cos(), and sinh().
=============================================
Standard C Date & Time
asctime
Syntax:

  #include <time.h>
  char *asctime( const struct tm *ptr );

The function asctime() converts the time in the struct ptr to a character string of the following format:

    day month date hours:minutes:seconds year/n/0

An example:

    Mon Jun 26 12:03:53 2000

Related topics:
localtime(), gmtime(), time(), and ctime().
clock
Syntax:

  #include <time.h>
  clock_t clock( void );

The clock() function returns the processor time since the program started, or -1 if that information is unavailable. To

convert the return value to seconds, divide it by CLOCKS_PER_SEC. (Note: if your compiler is POSIX compliant, then

CLOCKS_PER_SEC is always defined as 1000000.)
Related topics:
time(), asctime(), and ctime().
ctime
Syntax:

  #include <time.h>
  char *ctime( const time_t *time );

The ctime() function converts the calendar time time to local time of the format:

    day month date hours:minutes:seconds year/n/0

using ctime() is equivalent to

    asctime( localtime( tp ) );

Related topics:
localtime(), gmtime(), time(), and asctime().
difftime
Syntax:

  #include <time.h>
  double difftime( time_t time2, time_t time1 );

The function difftime() returns time2-time1, in seconds.
Related topics:
localtime(), gmtime(), time(), and asctime().
gmtime
Syntax:

  #include <time.h>
  struct tm *gmtime( const time_t *time );

The gmtime() function returns the given time in Coordinated Universal Time (usually Greenwich mean time), unless it's not

supported by the system, in which case NULL is returned. Warning!
Related topics:
localtime(), time(), and asctime().
localtime
Syntax:

  #include <time.h>
  struct tm *localtime( const time_t *time );

The function localtime() converts calendar time time into local time. Warning!
Related topics:
gmtime(), time(), and asctime().
mktime
Syntax:

  #include <time.h>
  time_t mktime( struct tm *time );

The mktime() function converts the local time in time to calendar time, and returns it. If there is an error, -1 is returned.
Related topics:
time(), gmtime(), asctime(), and ctime().
strftime
Syntax:

  #include <time.h>
  size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );

The function strftime() formats date and time information from time to a format specified by fmt, then stores the result in

str (up to maxsize characters). Certain codes may be used in fmt to specify different types of time:
Code  Meaning
%a  abbreviated weekday name
%A  full weekday name
%b  abbreviated month name
%B  full month name
%c  the standard date and time string
%d  day of the month, as a number (1-31)
%H  hour, 24 hour format (0-23)
%I  hour, 12 hour format (1-12)
%j  day of the year, as a number (1-366)
%m  month as a number (1-12). Note: some versions of Microsoft Visual C++ may use values that range from 0-11.
%M  minute as a number (0-59)
%p  locale's equivalent of AM or PM
%S  second as a number (0-59)
%U  week of the year, sunday as the first day
%w  weekday as a decimal (0-6, sunday=0)
%W  week of the year, monday as the first day
%x  standard date string
%X  standard time string
%y  year in decimal, without the century (0-99)
%Y  year in decimal, with the century
%Z  time zone name
%%  a percent sign

The strftime() function returns the number of characters put into str, or zero if an error occurs.
Related topics:
time(), localtime(), and gmtime().
time
Syntax:

  #include <time.h>
  time_t time( time_t *time );

The function time() returns the current time, or -1 if there is an error. If the argument time is given, then the current

time is stored in time.
Related topics:
localtime(), gmtime(), strftime(), ctime(),
=============================================
Standard C Memory
calloc
Syntax:

  #include <stdlib.h>
  void *calloc( size_t num, size_t size );

The calloc() function returns a pointer to space for an array of num objects, each of size size. calloc() returns NULL if

there is an error.
Related topics:
free(), malloc(), and realloc().
free
Syntax:

  #include <stdlib.h>
  void free( void *ptr );

The free() function deallocates the space pointed to by ptr, freeing it up for future use. ptr must have been used in a

previous call to malloc(), calloc(), or realloc(). An example:

    typedef struct data_type {
      int age;
      char name[20];
    } data;
   
    data *willy;
    willy = (data*) malloc( sizeof(willy) );
    ...
    free( willy );

Related topics:
calloc(), malloc(), and realloc().
malloc
Syntax:

  #include <stdlib.h>
  void *malloc( size_t size );

The function malloc() returns a pointer to a chunk of memory of size size, or NULL if there is an error. The memory pointed

to will be on the heap, not the stack, so make sure to free it when you are done with it. An example:

    typedef struct data_type {
      int age;
      char name[20];
    } data;
   
    data *bob;
    bob = (data*) malloc( sizeof(data) );
    if( bob != NULL ) {
      bob->age = 22;
      strcpy( bob->name, "Robert" );
      printf( "%s is %d years old/n", bob->name, bob->age );
    }
    free( bob );

Related topics:
free(), realloc(), and calloc().
realloc
Syntax:

  #include <stdlib.h>
  void *realloc( void *ptr, size_t size );

The realloc() function changes the size of the object pointed to by ptr to the given size. size can be any size, larger or

smaller than the original. The return value is a pointer to the new space, or NULL if there is an error.
Related topics:
free(), malloc(), and calloc().
=============================================
abort
Syntax:

  #include <stdlib.h>
  void abort( void );

The function abort() terminates the current program. Depending on the implementation, the return value can indicate failure.
Related topics:
exit() and atexit().
assert
Syntax:

  #include <assert.h>
  void assert( int exp );

The assert() macro is used to test for errors. If exp evaluates to zero, assert() writes information to STDERR and exits the

program. If the macro NDEBUG is defined, the assert() macros will be ignored.
Related topics:
abort()
atexit
Syntax:

  #include <stdlib.h>
  int atexit( void (*func)(void) );

The function atexit() causes the function pointed to by func to be called when the program terminates. You can make multiple

calls to atexit() (at least 32, depending on your compiler) and those functions will be called in reverse order of their

establishment. The return value of atexit() is zero upon success, and nonzero on failure.
Related topics:
exit() and abort().
bsearch
Syntax:

  #include <stdlib.h>
  void *bsearch( const void *key, const void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );

The bsearch() function searches buf[0] to buf[num-1] for an item that matches key, using a binary search. The function

compare should return negative if its first argument is less than its second, zero if equal, and positive if greater. The

items in the array buf should be in ascending order. The return value of bsearch() is a pointer to the matching item, or NULL

if none is found.
Related topics:
qsort().
exit
Syntax:

  #include <stdlib.h>
  void exit( int exit_code );

The exit() function stops the program. exit_code is passed on to be the return value of the program, where usually zero

indicates success and non-zero indicates an error.
Related topics:
atexit() and abort().
getenv
Syntax:

  #include <stdlib.h>
  char *getenv( const char *name );

The function getenv() returns environmental information associated with name, and is very implementation dependent. NULL is

returned if no information about name is available.
Related topics:
system().
longjmp
Syntax:

  #include <setjmp.h>
  void longjmp( jmp_buf envbuf, int status );

The function longjmp() causes the program to start executing code at the point of the last call to setjmp(). envbuf is

usually set through a call to setjmp(). status becomes the return value of setjmp() and can be used to figure out where

longjmp() came from. status should not be set to zero.
Related topics:
setjmp().
qsort
Syntax:

  #include <stdlib.h>
  void qsort( void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );

The qsort() function sorts buf (which contains num items, each of size size) using Quicksort. The compare function is used to

compare the items in buf. compare should return negative if the first argument is less than the second, zero if they are

equal, and positive if the first argument is greater than the second. qsort() sorts buf in ascending order.
Related topics:
bsearch().
raise
Syntax:

  #include <signal.h>
  int raise( int signal );

The raise() function sends the specified signal to the program. Some signals:
Signal  Meaning
SIGABRT  Termination error
SIGFPE  Floating pointer error
SIGILL  Bad instruction
SIGINT  User presed CTRL-C
SIGSEGV  Illegal memory access
SIGTERM  Terminate program

The return value is zero upon success, nonzero on failure.
Related topics:
signal()
rand
Syntax:

  #include <stdlib.h>
  int rand( void );

The function rand() returns a pseudorandom integer between zero and RAND_MAX. An example:

    srand( time(NULL) );
    for( i = 0; i < 10; i++ )
      printf( "Random number #%d: %d/n", i, rand() );

Related topics:
srand()
setjmp
Syntax:

  #include <setjmp.h>
  int setjmp( jmp_buf envbuf );

The setjmp() function saves the system stack in envbuf for use by a later call to longjmp(). When you first call setjmp(),

its return value is zero. Later, when you call longjmp(), the second argument of longjmp() is what the return value of

setjmp() will be. Confused? Read about longjmp().
Related topics:
longjmp()
signal
Syntax:

  #include <signal.h>
  void ( *signal( int signal, void (* func) (int)) ) (int);

The signal() function sets func to be called when signal is recieved by your program. func can be a custom signal handler, or

one of these macros (defined in signal.h):
Macro  Explanation
SIG_DFL  default signal handling
SIG_IGN  ignore the signal

The return value of signal() is the address of the previously defined function for this signal, or SIG_ERR is there is an

error.
srand
Syntax:

  #include <stdlib.h>
  void srand( unsigned seed );

The function srand() is used to seed the random sequence generated by rand(). For any given seed, rand() will generate a

specific "random" sequence over and over again.

    srand( time(NULL) );
    for( i = 0; i < 10; i++ )
      printf( "Random number #%d: %d/n", i, rand() );

Related topics:
rand(), time().
system
Syntax:

  #include <stdlib.h>
  int system( const char *command );

The system() function runs the given command as a system call. The return value is usually zero if the command executed

without errors. If command is NULL, system() will test to see if there is a command interpreter available. Non-zero will be

returned if there is a command interpreter available, zero if not.
Related topics:
exit(),
va_arg
Syntax:

  #include <stdarg.h>
  type va_arg( va_list argptr, type );
  void va_end( va_list argptr );
  void va_start( va_list argptr, last_parm );

The va_arg() macros are used to pass a variable number of arguments to a function.

   1. First, you must have a call to va_start() passing a valid va_list and the mandatory first argument of the function.

This first argument describes the number of parameters being passed.
   2. Next, you call va_arg() passing the va_list and the type of the argument to be returned. The return value of va_arg()

is the current parameter.
   3. Repeat calls to va_arg() for however many arguments you have.
   4. Finally, a call to va_end() passing the va_list is necessary for proper cleanup.

For example:

    int sum( int, ... );
    int main( void ) {
   
      int answer = sum( 4, 4, 3, 2, 1 );
      printf( "The answer is %d/n", answer );
   
      return( 0 );
    }
   
    int sum( int num, ... ) {
      int answer = 0;
      va_list argptr;
   
      va_start( argptr, num );
      for( ; num > 0; num-- )
        answer += va_arg( argptr, int );
   
      va_end( argptr );
      return( answer );
    }

This code displays 10, which is 4+3+2+1.
=============================================

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值