Topic : An introduction to C
Author : Tom Torfs
Page : << Previous 25  Next >>
Go to page :


of memory should not overlap. Returns the value of s1.

void *memmove(void *s1, const void *s2, size_t n);

Analogous to memcpy(), but supports overlapping memory areas.

void *memset(void *s, int c, size_t n);

Initializes the first n bytes of the memory pointed to by s to the value c (converted to unsigned char).

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

Appends a copy of the string pointed to by s2 (including the 0 terminator byte) to the end of the string pointed to by s1. The areas of memory should not overlap. Returns the value of s1.

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

Returns a pointer to the first occurence of the character c (converted to char) in the string pointed to by s, or NULL if none is found.

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

Compares the string pointed to by s1 with the string pointed to by s2. Returns a strictly negative value if s1 comes before s2, a strictly positive value if s1 comes after s2, or 0 if they match.

int strcoll(const char *s1, const char *s2);

Analogous to strcmp(), but interprets the strings according to the LC_COLLATE category of the current locale.

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

Copies the string pointed to by s2 (upto and including the 0 terminator byte) into the array pointed to by s1. The areas of memory should not overlap. Returns the value of s1.

size_t strcspn(const char *s1, const char *s2);

Returns the maximum length of the substring in the beginning of the string pointed to by s1 which does not contain any characters from the string pointed to by s2.

char *strerror(int errnum);

Returns a pointer to an error message string corresponding to the error number specified in errnum. The string is read-only, but may be modified by subsequent calls to the strerror() function.

size_t strlen(const char *s);

Returns the length of the string pointed to by s (excluding the 0 terminating character).

char *strncat(char *s1, const char *s2, size_t n);

Similar to strcat(), but appends no more than n characters. The areas of memory should not overlap. Returns the value of s1.
This function may produce an unterminated "string" if the limit of n characters is reached.

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

Similar to strcmp(), but compares no more than n characters.

char *strncpy(char *s1, const char *s2, size_t n);

Similar to strcpy(), but copies no more than n characters, and if the string is shorter than n characters s2 is padded with 0 characters. The areas of memory should not overlap. Returns the value of s1.
This function may produce an unterminated "string" if the limit of n characters is reached.

char *strpbrk(const char *s1, const char *s2);

Returns a pointer to the first occurence in the string pointed to by s1 of any character from the string pointed to by s2, or NULL if none was found.

char *strrchr(const char *s, int c);

Returns a pointer to the last occurence of the character c (converted to char) in the string pointed to by s, or NULL if none is found.

size_t strspn(const char *s1, const char *s2);

Returns the maximum length of the substring in the beginning of the string pointed to by s1 which contains only characters from the string pointed to by s2.

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

Returns a pointer to the first occurence of the substring pointed to by s2 in the string pointed to by s1, or NULL if none is found.

char *strtok(char *s1, const char *s2);

The first call to strtok() should pass the string to be processed as parameter s1 (note that this string will be modified by the strtok() function) and a string consisting of delimiting characters as parameter s2. The function will return a pointer to the first substring (token) that consists entirely of characters not in s2, with the first occurence of a delimiting character from s2 being overwritten with the 0 character.
Subsequent calls to strtok() should pass NULL for s1, which will cause strtok() to automatically continue with the next token. The string of delimiting characters s2 may be different each time.
The strtok() function will return NULL as soon as no more tokens can be found.

size_t strxfrm(char *s1, const char *s2, size_t n);

Transforms the string pointed to by s2 into the array pointed to by s1, with no more than n characters being written. Two transformed strings will compare identical using the strcmp() function as the original strings would using the strcoll() function. Returns the length of the transformed string, not including the terminating 0 character.16.16. time.h (date and time)
Types

clock_t

Arithmetic type returned by the clock() function.

size_t

Explained in 16.12. stddef.h.

time_t

Arithmetic type used to hold a time.

struct tm {
   int tm_sec;                /*  seconds after the minute [0..60] */
   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 */
  };


Structure used to hold a broken-down calendar time. The value of tm_isdst is strictly positive if daylight saving time is in effect, zero if it is not in effect, and negative if it is unknown.
Macros

CLOCKS_PER_SEC

Number of units per second of the value returned by clock(); replaces the earlier CLK_TCK.

NULL

Explained in 16.12. stddef.h.
Functions

char *asctime(const struct tm *timeptr);

Converts the broken-down calendar time in the structure pointed to by timeptr to a string of the form:

   Sun Sep 16 01:03:52 1973\n\0

Where the weekday name is one of:

   Sun, Mon, Tue, Wed, Thu, Fri, Sat

And the month name is one of:

   Jan, Feb, Mar, Apr, May, Jun,
   Jul, Aug, Sep, Oct, Nov, Dec

A pointer to the string is returned. This string may be modified by subsequent calls to asctime() or ctime().

clock_t clock(void);

Returns an approximation to the processor time used since a certain, unspecified starting point. By dividing the difference between two calls to clock() by CLOCKS_PER_SEC, the processor time used can be calculated in seconds. If the processor time is not available (clock_t)-1 is returned.

char *ctime(const time_t *timer);

A call to the ctime() function is equivalent to asctime(localtime(timer)).

double difftime(time_t time1, time_t time0);

Returns the difference in seconds between two calendar times (time1 - time0) as a double.

struct tm *gmtime(const time_t *timer);

Returns a pointer to the broken-down UTC time corresponding to the specified time_t value, or NULL if UTC is not available. The broken-down time structure may be modified by subsequent calls to gmtime(), localtime() or ctime().

struct tm *localtime(const time_t *timer);

Returns a pointer to the broken-down local time corresponding to the specified time_t value. The broken-down time structure may be modified by subsequent calls to localtime(), gmtime() or ctime().

time_t mktime(struct tm *timeptr);

Converts a broken-down local calendar time (see above for the structure definition) in the structure pointed to by timeptr to a time encoded as a value of type time_t.
Before the conversion, the tm_wday and tm_yday member variables need not be set and the other member variables need not be restricted to the above specified ranges. After the conversion, the tm_wday and tm_yday member variables will be filled in and the other member variables will be adjusted to the specified ranges.
Returns the encoded time value, or (time_t)-1 if the calendar time can't be represented.

size_t strftime(char *s, size_t maxsize,
                const char *format, const struct tm *timeptr);


The strftime() function works in similar way as the sprintf() function, except that it is used exclusively for formatting a broken-down time structure, pointed to by timeptr.
No more than maxsize characters are written in the array pointed to by s. The number of characters written (including the 0 character) is returned, unless

Page : << Previous 25  Next >>