In this section, we describe some of the more important routines in the standard C library. As we indicated previously, libc contains the system calls described in the Section 2 manual pages, and the C language functions described in Sections 3C and 3S. We'll explain what each of these subsections contains below. We'll look at system calls at the end of the section.
Subsection 3C contains functions and macros that perform a variety of tasks:
``String operations'' lists string-handling functions that appear on the string(3C) manual page. Programs that use these functions should include the header file <string.h>.
|Append a copy of one string to the end of another.
|Append no more than a given number of characters from one string to the end of another.
|Compare two strings. Returns an integer less than, greater than, or equal to 0 to show that one is lexicographically less than, greater than, or equal to the other.
|Compare no more than a given number of characters from the two strings. Results are otherwise identical to strcmp.
|Copy a string.
|Copy a given number of characters from one string to another. The destination string will be truncated if it is longer than the given number of characters, or padded with null characters if it is shorter.
|Return a pointer to a newly allocated string that is a duplicate of a string pointed to.
|Return a pointer to the first occurrence of a character in a string, or a null pointer if the character is not in the string.
|Return a pointer to the last occurrence of a character in a string, or a null pointer if the character is not in the string.
|Return the number of characters in a string.
|Return a pointer to the first occurrence in one string of any character from the second, or a null pointer if no character from the second occurs in the first.
|Return the length of the initial segment of one string that consists entirely of characters from the second string.
|Return the length of the initial segment of one string that consists entirely of characters not from the second string.
|Return a pointer to the first occurrence of the second string in the first string, or a null pointer if the second string is not found.
|Break up the first string into a sequence of tokens, each of which is delimited by one or more characters from the second string. Return a pointer to the token, or a null pointer if no token is found.
``Classifying 8-Bit character-coded integer values'' lists functions and macros that classify 8-bit character-coded integer values. These routines appear on the conv(3C) and ctype(3C) manual pages. Programs that use these routines should include the header file <ctype.h>.
Classifying 8-Bit character-coded integer values
|Is c a letter?
|Is c an uppercase letter?
|Is c a lowercase letter?
|Is c a digit [0-9]?
|Is c a hexadecimal digit [0-9], [A-F], or [a-f]?
|Is c alphanumeric (a letter or digit)?
|Is c a space, horizontal tab, vertical tab, new-line, form-feed, or carriage return?
|Is c a punctuation character (neither control nor alphanumeric)?
|Is c a printing character?
|Same as isprint except false for a space.
|Is c a control character or a delete character?
|Is c an ASCII character?
|Change lower case to upper case.
|Macro version of toupper.
|Change upper case to lower case.
|Macro version of tolower.
|Turn off all bits that are not part of a standard ASCII character; intended for compatibility with other systems.
``Converting characters, integers, or strings'' lists functions and macros in Section 3C that are used to convert characters, integers, or strings from one representation to another. The left-hand column contains the name that appears at the top of the manual page; the other names in the same row are related functions or macros described on the same manual page. Programs that use these routines should include the header file <stdlib.h>.
Converting characters, integers, or strings
|Convert string to double-precision number.
|strtol atol atoi
|Convert string to integer.
|Convert string to unsigned long.
|Print formatted output.
Subsection 3S contains the standard I/O library for C programs. Frequently, one manual page describes several related functions or macros. In ``Standard I/O functions and macros'', the left-hand column contains the name that appears at the top of the manual page; the other names in the same row are related functions or macros described on the same manual page. Programs that use these routines should include the header file <stdio.h>. We will talk a bit more about standard I/O in ``Standard I/O library''.
Standard I/O functions and macros
|Close or flush a stream.
|ferror feof clearerr fileno
|Stream status inquiries.
|fopen freopen fdopen
|Open a stream.
|fseek rewind ftell
|Reposition a file pointer in a stream.
|getc getchar fgetc getw
|Get a character or word from a stream.
|Get a string from a stream.
|Begin or end a pipe to/from a process.
|printf fprintf sprintf
|Print formatted output.
|putc putchar fputc putw
|Put a character or word on a stream.
|Put a string on a stream.
|scanf fscanf sscanf
|Convert formatted input.
|Assign buffering to a stream.
|Issue a command through the shell.
|Create a temporary file.
|Create a name for a temporary file.
|Push character back into input stream.
|vprintf vfprintf vsprintf
|Print formatted output of a varargs argument list.