DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
System calls and libraries

C library (libc)

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 S manual pages, and the C language functions described in Section S. We'll explain what each of these subsections contains below. We'll look at system calls at the end of the section.

String and Character routines

String and character functions and macros perform a variety of tasks:

``String operations'' lists string-handling functions that appear on the string(S) manual page. Programs that use these functions should include the header file <string.h>.

String operations

strcat Append a copy of one string to the end of another.
strncat Append no more than a given number of characters from one string to the end of another.
strcmp 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.
strncmp Compare no more than a given number of characters from the two strings. Results are otherwise identical to strcmp.
strcpy Copy a string.
strncpy 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.
strdup Return a pointer to a newly allocated string that is a duplicate of a string pointed to.
strchr 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.
strrchr 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.
strlen Return the number of characters in a string.
strpbrk 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.
strspn Return the length of the initial segment of one string that consists entirely of characters from the second string.
strcspn Return the length of the initial segment of one string that consists entirely of characters not from the second string.
strstr 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.
strtok 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(S) and ctype(S) manual pages. Programs that use these routines should include the header file <ctype.h>.

Classifying 8-Bit character-coded integer values

isalpha Is c a letter?
isupper Is c an uppercase letter?
islower Is c a lowercase letter?
isdigit Is c a digit [0-9]?
isxdigit Is c a hexadecimal digit [0-9], [A-F], or [a-f]?
isalnum Is c alphanumeric (a letter or digit)?
isspace Is c a space, horizontal tab, vertical tab, new-line, form-feed, or carriage return?
ispunct Is c a punctuation character (neither control nor alphanumeric)?
isprint Is c a printing character?
isgraph Same as isprint except false for a space.
iscntrl Is c a control character or a delete character?
isascii Is c an ASCII character?
toupper Change lower case to upper case.
_toupper Macro version of toupper.
tolower Change upper case to lower case.
_tolower Macro version of tolower.
toascii 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

strtod atof Convert string to double-precision number.
strtol atol atoi Convert string to integer.
strtoul Convert string to unsigned long.
sprintf Print formatted output.

Standard I/O routines

The standard I/O library routines for C programs are listed below. 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

fclose fflush Close or flush a stream.
ferror feof clearerr fileno Stream status inquiries.
fopen freopen fdopen Open a stream.
fread fwrite Input/output.
fseek rewind ftell Reposition a file pointer in a stream.
getc getchar fgetc getw Get a character or word from a stream.
gets fgets Get a string from a stream.
popen pclose 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.
puts fputs Put a string on a stream.
scanf fscanf sscanf Convert formatted input.
setbuf setvbuf Assign buffering to a stream.
system Issue a command through the shell.
tmpfile Create a temporary file.
tmpnam tempnam Create a name for a temporary file.
ungetc Push character back into input stream.
vprintf vfprintf vsprintf Print formatted output of a varargs argument list.


Next topic: Math library (libm)
Previous topic: How strcmp is used in a program

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005