Selected Standard Functions

 

In header file <ctype.h>:

int isalnum (int c)

Is c alphanumeric.

int isalpha (int c)

Is c alphabetic (a letter).

int iscntrl (int c)

Is c a control character.

int isdigit (int c)

Is c a decimal digit.

int ingraph (int c)

Is c a graphic character.

int islower (int c)

Is c a lower-case letter.

int isprint (int c)

Is c a printable character.

int ispunct (int c)

Is c a punctuation mark.

int isspace (int c)

Is c a white-space (space, tab, etc.)

int isupper (int c)

Is c an upper-case letter.

int isxdigit (int c)

Is c an hexadecimal digit (0-9 or A-F or a-f).

int tolower (int c)

Convert c to lower-case.

Int toupper (int c)

Convert c to upper-case.

 

In header file <math.h>:

double fabs (double x)

Compute the absolute value of x (|x|).

double ceil (double x)

Get the minimal integer greater than x (its ceiling).

double floor (double x)

Get the maximal integer less than x (its floor).

double sqrt (double x)

Compute the square-root of x.

double pow (double x,
            double y)

Compute x raised to the power of y (xy).

double sin (double x)

Compute the sine of x (given in radians).

double cos (double x)

Compute the cosine of x (given in radians).

double tan (double x)

Compute the tangent of x (given in radians).

double asin (double x)

Compute the arcsine of x (x between 0 and 1).

double acos (double x)

Compute the arccosine of x (x between 0 and 1).

double atan (double x)

Compute the arctangent of x.

double atan2 (double y,
              double x)

Compute the arctangent of y/x (x may be 0).

double sinh (double x)

Compute the hyperbolic sine of x.

double cosh (double x)

Compute the hyperbolic cosine of x.

double tanh (double x)

Compute the hyperbolic tangent of x.

double exp (double x)

Compute the exponent of x (ex).

double log (double x)

Compute the natural logarithm of x (ln x).

double log10 (double x)

Compute the base 10 logarithm of x.

 

In header file <stdio.h>:

int getchar ()

Read an input character and return it.

int putchar (int c)

Print the character c.

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

Write out formatted text, as indicated by the format string.

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

Read values from the standard input, as indicated by the format string.

FILE *fopen
   (const char *filename,
    const char *mode)

Open a file name filename in the given mode (“r” for reading, “w” for writing, “a” for appending). The function returns a pointer to the file, or NULL in case of failure.

int fgetc (FILE *p_file)

Read the next character from the input file p_file.
The function returns EOF if the end-of-file was reached.

int fputc (int c,
           FILE *p_file)

Write the character c to the output file p_file.

int feof (FILE *p_file)

Check whether we have reached the end of the file p_file (returns a non-zero value if we have).

char *fgets (char *line,
             int n,
             FILE *p_file)

Read the next line from the input file p_file (until and including the new-line character) to the string line. At most n-1 characters are read.
The function returns NULL if we reached end-of-file.

char *fputs (char *s,
             FILE *p_file)

Write the string s to the output file p_file.

int fprintf
   (FILE *p_file,
    const char *format, ...)

Write the formatted text, as indicated by the format string, to the output file p_file.

int fscanf
   (FILE *p_file,
    const char *format, ...)

Read values from the input file p_file, as indicated by the format string.

int flcose (FILE *p_file)

Close the file p_file.

 

In header file <stdlib.h>:

int abs (int a)

Return the absolute value of an integer.

unsigned time (void *)

Return the current time (the number of seconds elapsed since 1.1.1970).

void srand (unsigned s)

Seed the random number generator.

int rand ()

Return a random integer value between 0 and RAND_MAX.

void abort()

Abort the program.

void exit (int status)

Terminate the program with the given status code (usually 0 for a normal termination, and a non-zero value otherwise).

double atof (const char *s)

Convert the string s to a real number.

int atoi (char char *s)

Convert the string s to an integer number.

void *malloc (unsigned n)

Allocate a memory block of n bytes.

void *realloc (void *p,
               unsigned n)

Re-allocate the memory block pointed by p such that its size will be n (the contents of the existing blocks are preserved).

void free (void *p)

Free the memory block pointed by p.

 

In header file <string.h>:

int strlen (const char *s)

Get the length of the string (without the terminating NULL).

int strcmp (const char *s1,
            const char *s2)

Compare the two strings lexicographically. The returned value is less than, equal to or greater than 0 depending on whether s1 is  less than, equal to or greater than s2.

int strncmp (const char *s1,
             const char *s2,
             int n)

As above, but only the first n characters are compared.

char *strchr (const char *s,
              char c)

Find the first occurrence of the character c within the string s. If it is found, its address is returned – otherwise the function returns NULL.

char *strstr(const char *s1,
             const char *s2)

Find the first occurrence of the string s2 within the string s1. If it is found, its address is returned – otherwise the function returns NULL.

char *strcpy(char *s1,
             const char *s2)

Copy the string s2 to the string s1. Notice that s1 should be allocated with at least strlen(s2) bytes.

char *strncpy(char *s1,
             const char *s2,
             int n)

Copy the first n characters of string s2 to the string s1. Notice that s1 should be allocated with at least n bytes.

char *strcat(char *s1,
             const char *s2)

Concatenate the string s2 to the string s1. Notice that s1 should be allocated with at least
strlen(s1) +strlen(s2) bytes.

void *memcpy (void *p1,
              void *p2,
              int n)

Copy n bytes from p2 to p1.
The two memory blocks must not overlap.

void *memmov (void *p1,
              void *p2,
              int n)

Copy n bytes from p2 to p1.
The two memory blocks may overlap.