DEC C
Language Reference Manual
char*strchr(const char *s, int
c);
- Locates the first occurrence of c (converted to a char) in the string pointed to by s.
The terminating null character is considered to be part of the string.
The function returns a pointer to the located character, or a null
pointer if the character was not found.
size_t strcspn(const char *s1, const char
*s2);
- Computes the length of the maximum initial segment of the string
pointed to by s1 that consists entirely of characters not
found in the string pointed to by s2. The strcspn function returns the length of the
segment.
char*strpbrk(const char *s1, const char
*s2);
- Locates the first occurrence in the string pointed to by
s1 of any character from the string pointed to by s2.
The function returns a pointer to the character, or a null pointer if
no character in s1 occurs in s2.
char*strrchr(const char *s, int
c);
- Locates the last occurrence of c (converted to a char) in the string pointed to by s.
The terminating null character is considered to be part of the string.
The function returns a pointer to the located character, or a null
pointer if the character was not found.
size_t strspn(const char *s1, const char
*s2);
- Computes the length of the maximum initial segment of the string
pointed to by s1 that consists entirely of characters from the
string pointed to by s2. The strspn function returns the length of the
segment.
char*strstr(const char *s1, const char
*s2);
- Locates the first occurrence in the string pointed to by
s1 of the sequence of characters (excluding the terminal null
character) in the string pointed to by s2. The strstr function returns a pointer to the
located string, or a null pointer if the string was not found. If
s2 points to a string of zero length, the function returns
s1.
char*strtok(const char *s1, char
*s2);
- Breaks the string pointed to by s1 into a sequence of
tokens, each of which is delimited by a character from the string
pointed to by s2. The first call to strtok() skips characters, looking for the
first one that is not in s2. The function keeps track of its
position in the string pointed to by s1 between calls and, as
successive calls are made, the function works through this string,
identifying the text token following the one identified by the previous
call. When the function finds a character in s1 that matches a
character in s2, it replaces the character in s1 with
a null character. The strtok function
returns a pointer to the first character of the token, or a null
pointer if there is no token.
char*strerror(int errnum);
- Maps the error number in errnum to an
error message string; returns a pointer to the string. The string
pointed to must not be modified by the program, but can be overwritten
by a subsequent call to strerror.
size_t strlen(const char *s);
- Computes the length of the string pointed to by s. The
function returns the number of characters that precede the terminating
null character.
9.14 Date and Time (<time.h>)
The <time.h> header file defines
two macros, and declares four types and several functions for
manipulating time and date information. Some functions process local
time, which may differ from calendar time because of time zone.
Types
size_t
- An unsigned integral type of the result of the sizeof operator.
- Arithmetic types capable of representing times.
struct tm
- Holds the components of a calendar time, called the broken-down
time. The structure contains the following members:
int tm_sec; /* seconds after the minute -- [0,61] */
int tm_min; /* minutes after the hour -- [0,59] */
int tm_hour; /* hours since midnight -- [0,23] */
int tm_mday; /* day of the month -- [1,31] */
int tm_mon; /* months since January -- [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday -- [0,6] */
int tm_yday; /* days since January 1 -- [0,365] */
int tm_isdst; /* Daylight Saving Time flag -- 0 if */
/* DST not in effect; positive if it is; */
/* negative if information is not available. */
|
Macros
NULL
- Expands to an implementation-defined null pointer constant.
CLOCKS_PER_SEC
- The number per second of the value returned by the clock function.
Time Conversion Functions
char*asctime(const struct tm
*timeptr);
- Converts a broken-down time in the structure pointed to by
timeptr into a 26-character string in the form of this example:
Sat Sep 08 08:10:32 1990\n\0
|
A pointer to the string is returned.
char*ctime(const time_t *timer);
- Converts the calendar time pointed to by timer to local
time in a string of the form generated by the asctime function. A pointer to the string is
returned. The ctime function is
equivalent to the following:
asctime(localtime(timer))
|
struct tm*gmtime(const time_t
*timer);
- Converts the calendar time pointed to by timer into a
broken-down time expressed as Coordinated Universal Time (UTC). The
gmtime function returns a pointer to the
broken-down time, or a null pointer if UTC is not available.
struct tm*localtime(const time_t
*timer);
- Converts the calendar time pointed to by timer into a
broken-down time expressed as local time. The localtime function returns a pointer to the
broken-down time.
size_t strftime(char *s, size_t maxsize,
const char *format, const struct tm
*timeptr);
- Places characters into the array pointed to by s as
controlled by the string pointed to by format. The format
string consists of zero or more conversion specifiers and ordinary
multibyte characters. All ordinary multibyte characters (including the
terminating null character) are copied unchanged into the array. Each
conversion specifier is replaced by the appropriate characters as shown
in Table 9-2. The appropriate characters are determined by the
LC_TIME category of the current locale
and by the values contained in the structure pointed to by
timeptr.
Table 9-2 strftime Conversion Specifiers
Specifier |
Replaced by |
%a
|
The locale's abbreviated weekday name
|
%A
|
The locale's full weekday name
|
%b
|
The locale's abbreviated month name
|
%B
|
The locale's full month name
|
%c
|
The locale's appropriate date and time representation
|
%d
|
The day of the month as a decimal number (01 -- 31)
|
%H
|
The hour (24-hour clock) as a decimal number (00 -- 23)
|
%I
|
The hour (12-hour clock) as a decimal number (01 -- 12)
|
%j
|
The day of the year as a decimal number (001 -- 366)
|
%m
|
The month as a decimal number (01 -- 12)
|
%M
|
The minute as a decimal number (00 -- 59)
|
%p
|
The locale's equivalent of the AM/PM designations associated with a
12-hour clock
|
%S
|
The second as a decimal number (00 -- 61)
|
%U
|
The week number of the year (the first Sunday as the first day of week
1) as a decimal number (00 -- 53)
|
%w
|
The weekday as a decimal number (0 [Sunday] -- 6)
|
%W
|
The week number of the year (the first Monday as the first day of week
1) as a decimal number (00 -- 53)
|
%x
|
The locale's appropriate date representation
|
%X
|
The locale's appropriate time representation
|
%y
|
The year without century as a decimal number (00 -- 99)
|
%Y
|
The year with century as a decimal number
|
%Z
|
The time zone name or abbreviation, or by no characters if no time zone
can be determined
|
%%
|
%
|
If the total number of resulting characters including the
terminating null character is not more than maxsize, the strftime function returns the number of
characters placed into the array pointed to by s, not
including the terminating null character. Otherwise, 0 is returned, and
the array contents are indeterminate.
Time Manipulation Functions
clock_t clock(void);
- Determines the processor time used. The clock function returns the processor time used
by the program since the beginning of an event related to the program
invocation. To determine the time in seconds, divide the return value
by the value of the CLOCKS_PER_SEC macro.
If the processor time is not available or cannot be represented, the
value returned is (clock_t)-1. (To
measure the time spent in a program, call the clock function at the start of the program and
subtract the return value from that of subsequent calls.)
double difftime(time_t time1, time_t
time0);
- Returns the difference between the two calendar times
time1 and time0, expressed in seconds, as a double.
time_t mktime(struct tm
*timeptr);
- Converts the broken-down time, expressed as local time, in the
structure pointed to by timeptr into a calendar time value
with the same encoding as that of the values returned by the time function (that is, a value of type time_t), which it returns. If the calendar time
cannot be represented, the value (time_t)-1 is returned.
The original values
of the tm_wday and tm_yday time components are ignored, and the
original values of the other components are not restricted to the
ranges indicated in the previous discussion of struct_tm. Upon successful completion of the
function, the values of the tm_wday and
tm_yday components are set appropriately,
and the other components are set to represent the specified calendar
time, but with their values forced to the ranges indicated in the
discussion of struct_tm. The final value
of tm_wday is not set until tm_mon and tm_year are determined.
time_t time(time_t *timer);
- Returns the current calendar time. If the calendar time is not
available, the value (time_t)-1 is
returned.
Appendix A
Language Syntax Summary
This section summarizes the syntax of the C language, using the syntax
of the ANSI C Standard. Syntactic categories are indicated with
bold type, and literal words or characters are
indicated with monospaced, nonitalicized type. A colon following a
syntactic category introduces its definition. Alternative definitions
are listed on separate lines, or are prefaced by the words "one
of." An optional element is indicated by the subscript
opt. For example, the following line indicates an optional
expression enclosed in braces:
The section numbers shown in parentheses refer to the section of the
American National Standard for Information Systems-Programming
Language C (document number: X3.159-1989) that discusses that part
of the language.
A.1.1 Lexical Grammar
A.1.1.1 Tokens
token: (§3.1)
- keyword
- identifier
- constant
- string-literal
- operator
- punctuator
|
preprocessing-token: (§3.1)
- header-name
- identifier
- pp-number
- character-constant
- string-literal
- operator
- punctuator
- each nonwhite-space character that cannot be one of the above
|
A.1.1.2 Keywords
keyword: (§3.1.1) one of
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
|
A.1.1.3 Identifiers
identifier: (§3.1.2)
- nondigit
- identifier nondigit
- identifier digit
|
nondigit: §3.1.2 one of
a b c d e f g h i j k l m
n o p q r s t u v w x y z
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z _
|
digit: (§3.1.2) one of
A.1.1.4 Constants
constant: (§3.1.3)
- floating-constant
- integer-constant
- enumeration-constant
- character-constant
|
floating-constant: (§3.1.3.1)
- fractional-constant exponent-partopt
floating-suffixopt
- digit-sequence exponent-part floating-suffixopt
|
fractional-constant: (§3.1.3.1)
- digit-sequenceopt . digit-sequence
- digit-sequence .
|
exponent-part: (§3.1.3.1)
- e signopt digit-sequence
- E signopt digit-sequence
|
sign: (§3.1.3.1) one of
digit-sequence: (§3.1.3.1)
- digit
- digit-sequence digit
|
floating-suffix: (§3.1.3.1) one of
integer-constant: (§3.1.3.2)
- decimal-constant integer-suffixopt
- octal-constant integer-suffixopt
- hexadecimal-constant integer-suffixopt
|
decimal-constant: (§3.1.3.2)
- nonzero-digit
- decimal-constant digit
|
octal-constant: (§3.1.3.2)
- 0
- octal-constant octal-digit
|
hexadecimal-constant: (§3.1.3.2)
- 0x hexadecimal-digit
- 0X hexadecimal-digit
- hexadecimal-constant hexadecimal-digit
|
nonzero-digit: (§3.1.3.2) one of
octal-digit: (§3.1.3.2) one of
hexadecimal-digit: (§3.1.3.2) one of
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F
|
integer-suffix: (§3.1.3.2)
- unsigned-suffix long-suffixopt
- long-suffix unsigned-suffixopt
|
unsigned-suffix: (§3.1.3.2) one of
long-suffix: (§3.1.3.2) one of
enumeration-constant: (§3.1.3.3)
character-constant: (§3.1.3.4)
- ' c-char-sequence'
- L' c-char-sequence'
|
c-char-sequence: (§3.1.3.4)
- c-char
- c-char-sequence c-char
|
c-char: (§3.1.3.4)
- any member of the source character set except
the single-quote ('), backslash (\), or new-line character
- escape-sequence
|
escape-sequence: (§3.1.3.4)
- simple-escape-sequence
- octal-escape-sequence
- hexadecimal-escape-sequence
|
simple-escape-sequence: (§3.1.3.4) one of
\' \" \? \\
\a \b \f \n \r \t \v
|
octal-escape-sequence: (§3.1.3.4)
- \ octal-digit
- \ octal-digit octal-digit
- \ octal-digit octal-digit octal-digit
|
hexadecimal-escape-sequence:(§3.1.3.4)
- \x hexadecimal-digit
- hexadecimal-escape-sequence hexadecimal-digit
|
A.1.1.5 String Literals
string-literal: (§3.1.4)
- "s-char-sequenceopt"
- L"s-char-sequenceopt"
|