The C Programming Language Flashcards
B.1 Input and Output: <stdio.h>
The input and output functions, types, and macros defined in <stdio.h> represent nearly onethird of the library.A stream is a source or destination of data that may be associated with a disk or otherperipheral. The library supports text streams and binary streams, although on some systems,notably UNIX, these are identical. A text stream is a sequence of lines; each line has zero ormore characters and is terminated by '\n'. An environment may need to convert a text streamto or from some other representation (such as mapping '\n' to carriage return and linefeed).A binary stream is a sequence of unprocessed bytes that record internal data, with the propertythat if it is written, then read back on the same system, it will compare equal.A stream is connected to a file or device by opening it; the connection is broken by closingthe stream. Opening a file returns a pointer to an object of type FILE, which records whateverinformation is necessary to control the stream. We will use ``file pointer'' and ``stream''interchangeably when there is no ambiguity.When
Table B.1 Printf Conversions
Character Argument type; Printed Asd,i int; signed decimal notation.o int; unsigned octal notation (without a leading zero).x,Xunsigned int; unsigned hexadecimal notation (without a leading 0x or 0X),using abcdef for 0x or ABCDEF for 0X.u int; unsigned decimal notation.c int; single character, after conversion to unsigned charschar *; characters from the string are printed until a '\0' is reached or until thenumber of characters indicated by the precision have been printed.fdouble; decimal notation of the form [-]mmm.ddd, where the number of d's isgiven by the precision. The default precision is 6; a precision of 0 suppresses the decimal point.e,Edouble; decimal notation of the form [-]m.dddddde+/-xx or [-]m.ddddddE+/-xx, where the number of d's is specified by the precision. The default precision is6; a precision of 0 suppresses the decimal point.g,Gdouble; %e or %E is used if the exponent is less than -4 or greater than or equal tothe precision; otherwise %f is used. Trailing zeros and a trailing decimal point arenot printed.p void *; print as a pointer (implementation-dependent representation).nint *; the number of characters written so far by this call to printf is writteninto the argument. No argument is converted.% no argument is converted; print a %int printf(const char *format, ...)printf(...) is equivalent to fprintf(stdout, ...).int sprintf(char s, const char format, ...)sprintf is the same as printf except that the output is written into the string s,terminated with '\0'. s must be big enough to hold the result. The return count doesnot include the '\0'.int vprintf(const char *format, va_list arg)int vfprintf(FILE stream, const char format, va_list arg)int vsprintf(char s, const char format, va_list arg)The functions vprintf, vfprintf, and vsprintf are equivalent to the correspondingprintf functions, except that the variable argument list is replaced by arg, which hasbeen initialized by the va_start macro and perhaps va_arg calls. See the discussionof <stdarg.h> in Section B.7.
B.1.1 File Operations
The following functions deal with operations on files. The type size_t is the unsignedintegral type produced by the sizeof operator.FILE fopen(const char filename, const char *mode)fopen opens the named file, and returns a stream, or NULL if the attempt fails. Legalvalues for mode include:"r" open text file for reading"w" create text file for writing; discard previous contents if any"a" append; open or create text file for writing at end of file"r+" open text file for update (i.e., reading and writing)"w+" create text file for update, discard previous contents if any"a+" append; open or create text file for update, writing at endUpdate mode permits reading and writing the same file; fflush or a file -positioningfunction must be called between a read and a write or vice versa. If the mode includesb after the initial letter, as in "rb" or "w+b", that indicates a binary file. Filenames arelimited to FILENAME_MAX characters. At most FOPEN_MAX files may be open at once.FILE freopen(const char filename, const char mode, FILE stream)freopen opens the file with the specified mode and associates the stream with it. Itreturns stream, or NULL if an error occurs. freopen is normally used to change thefiles associated with stdin, stdout, or stderr.int fflush(FILE *stream)On an output stream, fflush causes any buffered but unwritten data to be written; onan input stream, the effect is undefined. It returns EOF for a write error, and zerootherwise. fflush(NULL) flushes all output streams.int fclose(FILE *stream)fclose flushes any unwritten data for stream, discards any unread buffered input,frees any automatically allocated buffer, then closes the stream. It returns EOF if anyerrors occurred, and zero otherwise.int remove(const char *filename)remove removes the named file, so that a subsequent attempt to open it will fail. Itreturns non-zero if the attempt fails.int rename(const char oldname, const char newname)rename changes the name of a file; it returns non-zero if the attempt fails.FILE *tmpfile(void)tmpfile creates a temporary file of mode "wb+" that will be automatically removedwhen closed or when the program terminates normally. tmpfile returns a stream, orNULL if it could not create the file.char *tmpnam(char s[L_tmpnam])tmpnam(NULL) creates a string that is not the name of an existing file, and returns apointer to an internal static array. tmpnam(s) stores the string in s as well as returningit as the function value; s must have room for at least L_tmpnam characters. tmpnamgenerates a different name each time it is called; at most TMP_MAX different names areguaranteed during execution of the program. Note that tmpnam creates a name, not afile.int setvbuf(FILE stream, char buf, int mode, size_t size)setvbuf controls buffering for the stream; it must be called before reading, writing orany other operation. A mode of _IOFBF causes full buffering, _IOLBF line buffering oftext files, and _IONBF no buffering. If buf is not NULL, it will be used as the buffer,otherwise a buffer will be allocated. size determines the buffer size. setvbuf returnsnon-zero for any error.void setbuf(FILE stream, char buf)222If buf is NULL, buffering is turned off for the stream. Otherwise, setbuf is equivalentto (void) setvbuf(stream, buf, _IOFBF, BUFSIZ).
Table B.2 Scanf Conversions
Characters, Input Data; Argument typed decimal integer; int*iinteger; int*. The integer may be in octal (leading 0) or hexadecimal (leading 0xor 0X).o octal integer (with or without leading zero); int *.u unsigned decimal integer; unsigned int *.x hexadecimal integer (with or without leading 0x or 0X); int*.ccharacters; char*. The next input characters are placed in the indicated array, upto the number given by the width field; the default is 1. No '\0' is added. Thenormal skip over white space characters is suppressed in this case; to read the nextnon-white space character, use %1s.sstring of non-white space characters (not quoted); char *, pointing to an array ofcharacters large enough to hold the string and a terminating '\0' that will beadded.e,f,gfloating-point number; float *. The input format for float's is an optional sign,a string of numbers possibly containing a decimal point, and an optional exponentfield containing an E or e followed by a possibly signed integer.p pointer value as printed by printf("%p");, void *.nwrites into the argument the number of characters read so far by this call; int *.No input is read. The converted item count is not incremented.[...]matches the longest non-empty string of input characters from the set betweenbrackets; char *. A '\0' is added. []...] includes ] in the set.225[^...]matches the longest non-empty string of input characters not from the set betweenbrackets; char *. A '\0' is added. [^]...] includes ] in the set.% literal %; no assignment is made.int scanf(const char *format, ...)scanf(...) is identical to fscanf(stdin, ...).int sscanf(const char s, const char format, ...)sscanf(s, ...) is equivalent to scanf(...) except that the input characters aretaken from the string s.
B.1.4 Character Input and Output Functions
int fgetc(FILE *stream)fgetc returns the next character of stream as an unsigned char (converted to anint), or EOF if end of file or error occurs.char fgets(char s, int n, FILE *stream)fgets reads at most the next n-1 characters into the array s, stopping if a newline isencountered; the newline is included in the array, which is terminated by '\0'. fgetsreturns s, or NULL if end of file or error occurs.int fputc(int c, FILE *stream)fputc writes the character c (converted to an unsigend char) on stream. It returnsthe character written, or EOF for error.int fputs(const char s, FILE stream)fputs writes the string s (which need not contain \n) on stream; it returns nonnegative,or EOF for an error.int getc(FILE *stream)getc is equivalent to fgetc except that if it is a macro, it may evaluate stream morethan once.int getchar(void)getchar is equivalent to getc(stdin).char gets(char s)gets reads the next input line into the array s; it replaces the terminating newline with'\0'. It returns s, or NULL if end of file or error occurs.int putc(int c, FILE *stream)putc is equivalent to fputc except that if it is a macro, it may evaluate stream morethan once.int putchar(int c)putchar(c) is equivalent to putc(c,stdout).int puts(const char *s)puts writes the string s and a newline to stdout. It returns EOF if an error occurs,non-negative otherwise.int ungetc(int c, FILE *stream)ungetc pushes c (converted to an unsigned char) back onto stream, where it will bereturned on the next read. Only one character of pushback per stream is guaranteed.EOF may not be pushed back. ungetc returns the character pushed back, or EOF forerror.
B.1.5 Direct Input and Output Functions
size_t fread(void ptr, size_t size, size_t nobj, FILE stream)fread reads from stream into the array ptr at most nobj objects of size size. freadreturns the number of objects read; this may be less than the number requested. feofand ferror must be used to determine status.size_t fwrite(const void ptr, size_t size, size_t nobj, FILE stream)226fwrite writes, from the array ptr, nobj objects of size size on stream. It returns thenumber of objects written, which is less than nobj on error.
B.1.6 File Positioning Functions
int fseek(FILE *stream, long offset, int origin)fseek sets the file position for stream; a subsequent read or write will access databeginning at the new position. For a binary file, the position is set to offsetcharacters from origin, which may be SEEK_SET (beginning), SEEK_CUR (currentposition), or SEEK_END (end of file). For a text stream, offset must be zero, or a valuereturned by ftell (in which case origin must be SEEK_SET). fseek returns non-zeroon error.long ftell(FILE *stream)ftell returns the current file position for stream, or -1 on error.void rewind(FILE *stream)rewind(fp) is equivalent to fseek(fp, 0L, SEEK_SET); clearerr(fp).int fgetpos(FILE stream, fpos_t ptr)fgetpos records the current position in stream in *ptr, for subsequent use byfsetpos. The type fpos_t is suitable for recording such values. fgetpos returns nonzeroon error.int fsetpos(FILE stream, const fpos_t ptr)fsetpos positions stream at the position recorded by fgetpos in *ptr. fsetposreturns non-zero on error.
B.1.7 Error Functions
Many of the functions in the library set status indicators when error or end of file occur. Theseindicators may be set and tested explicitly. In addition, the integer expression errno (declaredin <errno.h>) may contain an error number that gives further information about the mostrecent error.void clearerr(FILE *stream)clearerr clears the end of file and error indicators for stream.int feof(FILE *stream)feof returns non-zero if the end of file indicator for stream is set.int ferror(FILE *stream)ferror returns non-zero if the error indicator for stream is set.void perror(const char *s)perror(s) prints s and an implementation-defined error message corresponding tothe integer in errno, as if byfprintf(stderr, "%s: %s\n", s, "error message");See strerror in Section B.3.
B.2 Character Class Tests: <ctype.h>
The header <ctype.h> declares functions for testing characters. For each function, theargument list is an int, whose value must be EOF or representable as an unsigned char, andthe return value is an int. The functions return non-zero (true) if the argument c satisfies thecondition described, and zero if not.isalnum(c) isalpha(c) or isdigit(c) is trueisalpha(c) isupper(c) or islower(c) is true227iscntrl(c) control characterisdigit(c) decimal digitisgraph(c) printing character except spaceislower(c) lower-case letterisprint(c) printing character including spaceispunct(c) printing character except space or letter or digitisspace(c) space, formfeed, newline, carriage return, tab, vertical tabisupper(c) upper-case letterisxdigit(c) hexadecimal digitIn the seven-bit ASCII character set, the printing characters are 0x20 (' ') to 0x7E ('-');the control characters are 0 NUL to 0x1F (US), and 0x7F (DEL).In addition, there are two functions that convert the case of letters:int tolower(c) convert c to lower caseint toupper(c) convert c to upper caseIf c is an upper-case letter, tolower(c) returns the corresponding lower-case letter,toupper(c) returns the corresponding upper-case letter; otherwise it returns c.
B.3 String Functions: <string.h>
There are two groups of string functions defined in the header <string.h>. The first havenames beginning with str; the second have names beginning with mem. Except for memmove,the behavior is undefined if copying takes place between overlapping objects. Comparisonfunctions treat arguments as unsigned char arrays.In the following table, variables s and t are of type char *; cs and ct are of type constchar *; n is of type size_t; and c is an int converted to char.char *strcpy(s,ct) copy string ct to string s, including '\0'; return s.char*strncpy(s,ct,n)copy at most n characters of string ct to s; return s. Pad with '\0''sif ct has fewer than n characters.char *strcat(s,ct) concatenate string ct to end of string s; return s.char*strncat(s,ct,n)concatenate at most n characters of string ct to string s, terminate swith '\0'; return s.int strcmp(cs,ct)compare string cs to string ct, return <0 if cs<ct, 0 if cs==ct, or >0if cs>ct.intstrncmp(cs,ct,n)compare at most n characters of string cs to string ct; return <0 ifcs<ct, 0 if cs==ct, or >0 if cs>ct.char *strchr(cs,c) return pointer to first occurrence of c in cs or NULL if not present.char *strrchr(cs,c) return pointer to last occurrence of c in cs or NULL if not present.size_tstrspn(cs,ct) return length of prefix of cs consisting of characters in ct.228size_tstrcspn(cs,ct)return length of prefix of cs consisting of characters not in ct.char*strpbrk(cs,ct)return pointer to first occurrence in string cs of any character stringct, or NULL if not present.char *strstr(cs,ct)return pointer to first occurrence of string ct in cs, or NULL if notpresent.size_t strlen(cs) return length of cs.char *strerror(n)return pointer to implementation-defined string corresponding toerror n.char *strtok(s,ct)strtok searches s for tokens delimited by characters from ct; seebelow.A sequence of calls of strtok(s,ct) splits s into tokens, each delimited by a character fromct. The first call in a sequence has a non-NULL s, it finds the first token in s consisting ofcharacters not in ct; it terminates that by overwriting the next character of s with '\0' andreturns a pointer to the token. Each subsequent call, indicated by a NULL value of s, returns thenext such token, searching from just past the end of the previous one. strtok returns NULLwhen no further token is found. The string ct may be different on each call.The mem... functions are meant for manipulating objects as character arrays; the intent is aninterface to efficient routines. In the following table, s and t are of type void *; cs and ctare of type const void *; n is of type size_t; and c is an int converted to an unsignedchar.void*memcpy(s,ct,n)copy n characters from ct to s, and return s.void*memmove(s,ct,n) same as memcpy except that it works even if the objects overlap.int memcmp(cs,ct,n) compare the first n characters of cs with ct; return as with strcmp.void*memchr(cs,c,n)return pointer to first occurrence of character c in cs, or NULL if notpresent among the first n characters.void *memset(s,c,n) place character c into first n characters of s, return s.
B.4 Mathematical Functions: <math.h>
The header <math.h> declares mathematical functions and macros.The macros EDOM and ERANGE (found in <errno.h>) are non-zero integral constants that areused to signal domain and range errors for the functions; HUGE_VAL is a positive doublevalue. A domain error occurs if an argument is outside the domain over which the function isdefined. On a domain error, errno is set to EDOM; the return value is implementation-defined.A range error occurs if the result of the function cannot be represented as a double. If theresult overflows, the function returns HUGE_VAL with the right sign, and errno is set toERANGE. If the result underflows, the function returns zero; whether errno is set to ERANGE isimplementation-defined.In the following table, x and y are of type double, n is an int, and all functions returndouble. Angles for trigonometric functions are expressed in radians.sin(x) sine of xcos(x) cosine of xtan(x) tangent of xasin(x) sin-1(x) in range [-pi/2,pi/2], x in [-1,1].acos(x) cos-1(x) in range [0,pi], x in [-1,1].atan(x) tan-1(x) in range [-pi/2,pi/2].atan2(y,x) tan-1(y/x) in range [-pi,pi].sinh(x) hyperbolic sine of xcosh(x) hyperbolic cosine of xtanh(x) hyperbolic tangent of xexp(x) exponential function exlog(x) natural logarithm ln(x), x>0.log10(x) base 10 logarithm log10(x), x>0.pow(x,y)xy. A domain error occurs if x=0 and y<=0, or if x<0 and y is not aninteger.sqrt(x) sqare root of x, x>=0.ceil(x) smallest integer not less than x, as a double.floor(x) largest integer not greater than x, as a double.fabs(x) absolute value |x|ldexp(x,n) x*2nfrexp(x, int*ip)splits x into a normalized fraction in the interval [1/2,1) which is returned,and a power of 2, which is stored in *exp. If x is zero, both parts of theresult are zero.modf(x,double *ip)splits x into integral and fractional parts, each with the same sign as x. Itstores the integral part in *ip, and returns the fractional part.fmod(x,y)floating-point remainder of x/y, with the same sign as x. If y is zero, theresult is implementation-defined.
B.5 Utility Functions: <stdlib.h>
The header <stdlib.h> declares functions for number conversion, storage allocation, andsimilar tasks. double atof(const char *s)atof converts s to double; it is equivalent to strtod(s, (char**)NULL).int atoi(const char *s)converts s to int; it is equivalent to (int)strtol(s, (char**)NULL, 10).long atol(const char *s)converts s to long; it is equivalent to strtol(s, (char**)NULL, 10).double strtod(const char s, char *endp)strtod converts the prefix of s to double, ignoring leading white space; it stores apointer to any unconverted suffix in *endp unless endp is NULL. If the answer wouldoverflow, HUGE_VAL is returned with the proper sign; if the answer would underflow,zero is returned. In either case errno is set to ERANGE.long strtol(const char s, char *endp, int base)strtol converts the prefix of s to long, ignoring leading white space; it stores apointer to any unconverted suffix in *endp unless endp is NULL. If base is between 2230and 36, conversion is done assuming that the input is written in that base. If base iszero, the base is 8, 10, or 16; leading 0 implies octal and leading 0x or 0Xhexadecimal. Letters in either case represent digits from 10 to base-1; a leading 0x or0X is permitted in base 16. If the answer would overflow, LONG_MAX or LONG_MIN isreturned, depending on the sign of the result, and errno is set to ERANGE.unsigned long strtoul(const char s, char *endp, int base)strtoul is the same as strtol except that the result is unsigned long and the errorvalue is ULONG_MAX.int rand(void)rand returns a pseudo-random integer in the range 0 to RAND_MAX, which is at least32767.void srand(unsigned int seed)srand uses seed as the seed for a new sequence of pseudo-random numbers. Theinitial seed is 1.void *calloc(size_t nobj, size_t size)calloc returns a pointer to space for an array of nobj objects, each of size size, orNULL if the request cannot be satisfied. The space is initialized to zero bytes.void *malloc(size_t size)malloc returns a pointer to space for an object of size size, or NULL if the requestcannot be satisfied. The space is uninitialized.void realloc(void p, size_t size)realloc changes the size of the object pointed to by p to size. The contents will beunchanged up to the minimum of the old and new sizes. If the new size is larger, thenew space is uninitialized. realloc returns a pointer to the new space, or NULL if therequest cannot be satisfied, in which case *p is unchanged.void free(void *p)free deallocates the space pointed to by p; it does nothing if p is NULL. p must be apointer to space previously allocated by calloc, malloc, or realloc.void abort(void)abort causes the program to terminate abnormally, as if by raise(SIGABRT).void exit(int status)exit causes normal program termination. atexit functions are called in reverse orderof registration, open files are flushed, open streams are closed, and control is returnedto the environment. How status is returned to the environment is implementationdependent,but zero is taken as successful termination. The values EXIT_SUCCESS andEXIT_FAILURE may also be used.int atexit(void (*fcn)(void))atexit registers the function fcn to be called when the program terminates normally;it returns non-zero if the registration cannot be made.int system(const char *s)system passes the string s to the environment for execution. If s is NULL, systemreturns non-zero if there is a command processor. If s is not NULL, the return value isimplementation-dependent.char getenv(const char name)getenv returns the environment string associated with name, or NULL if no stringexists. Details are implementation-dependent.void bsearch(const void key, const void *base,size_t n, size_t size,int (cmp)(const void keyval, const void *datum))bsearch searches base[0]...base[n-1] for an item that matches *key. The functioncmp must return negative if its first argument (the search key) is less than its second (atable entry), zero if equal, and positive if greater. Items in the array base must be inascending order. bsearch returns a pointer to a matching item, or NULL if none exists.231void qsort(void *base, size_t n, size_t size,int (cmp)(const void , const void *))qsort sorts into ascending order an array base[0]...base[n-1] of objects of sizesize. The comparison function cmp is as in bsearch.int abs(int n)abs returns the absolute value of its int argument.long labs(long n)labs returns the absolute value of its long argument.div_t div(int num, int denom)div computes the quotient and remainder of num/denom. The results are stored in theint members quot and rem of a structure of type div_t.ldiv_t ldiv(long num, long denom)ldiv computes the quotient and remainder of num/denom. The results are stored in thelong members quot and rem of a structure of type ldiv_t.
B.6 Diagnostics: <assert.h>
The assert macro is used to add diagnostics to programs:void assert(int expression)If expression is zero whenassert(expression)is executed, the assert macro will print on stderr a message, such asAssertion failed: expression, file filename, line nnnIt then calls abort to terminate execution. The source filename and line number come fromthe preprocessor macros __FILE__ and __LINE__.If NDEBUG is defined at the time <assert.h> is included, the assert macro is ignored.B.7 Variable Argument Lists: <stdarg.h>The header <stdarg.h> provides facilities for stepping through a list of function argumentsof unknown number and type.Suppose lastarg is the last named parameter of a function f with a variable number ofarguments. Then declare within f a variable of type va_list that will point to each argumentin turn:va_list ap;ap must be initialized once with the macro va_start before any unnamed argument isaccessed:va_start(va_list ap, lastarg);232Thereafter, each execution of the macro va_arg will produce a value that has the type andvalue of the next unnamed argument, and will also modify ap so the next use of va_argreturns the next argument:type va_arg(va_list ap, type);The macrovoid va_end(va_list ap);must be called once after the arguments have been processed but before f is exited.B.8 Non-local Jumps: <setjmp.h>The decla rations in <setjmp.h> provide a way to avoid the normal function call and returnsequence, typically to permit an immediate return from a deeply nested function call.int setjmp(jmp_buf env)The macro setjmp saves state information in env for use by longjmp. The return iszero from a direct call of setjmp, and non-zero from a subsequent call of longjmp. Acall to setjmp can only occur in certain contexts, basically the test of if, switch, andloops, and only in simple relational expressions.if (setjmp(env) == 0)/ get here on direct call /else/ get here by calling longjmp /void longjmp(jmp_buf env, int val)longjmp restores the state saved by the most recent call to setjmp, using theinformation saved in env, and execution resumes as if the setjmp function had justexecuted and returned the non-zero value val. The function containing the setjmpmust not have terminated. Accessible objects have the values they had at the timelongjmp was called, except that non-volatile automatic variables in the functioncalling setjmp become undefined if they were changed after the setjmp call.
B.9 Signals: <signal.h>
The header <signal.h> provides facilities for handling exceptional conditions that ariseduring execution, such as an interrupt signal from an external source or an error in execution.void (signal(int sig, void (handler)(int)))(int)signal determines how subsequent signals will be handled. If handler is SIG_DFL, theimplementation-defined default behavior is used, if it is SIG_IGN, the signal is ignored;otherwise, the function pointed to by handler will be called, with the argument of the type ofsignal. Valid signals includeSIGABRT abnormal termination, e.g., from abortSIGFPE arithmetic error, e.g., zero divide or overflowSIGILL illegal function image, e.g., illegal instructionSIGINT interactive attention, e.g., interruptSIGSEGV illegal storage access, e.g., access outside memory limitsSIGTERM termination request sent to this program233signal returns the previous value of handler for the specific signal, or SIG_ERR if an erroroccurs.When a signal sig subsequently occurs, the signal is restored to its default behavior; then thesignal-handler function is called, as if by (*handler)(sig). If the handler returns, executionwill resume where it was when the signal occurred.The initial state of signals is implementation-defined.int raise(int sig)raise sends the signal sig to the program; it returns non-zero if unsuccessful.
B.10 Date and Time Functions: <time.h>
The header <time.h> declares types and functions for manipulating date and time. Somefunctions process local time, which may differ from calendar time, for example because oftime zone. clock_t and time_t are arithmetic types representing times, and struct tm holdsthe components of a calendar time: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 1900int tm_wday; days since Sunday (0,6)int tm_yday; days since January 1 (0,365)int tm_isdst; Daylight Saving Time flagtm_isdst is positive if Daylight Saving Time is in effect, zero if not, and negative if theinformation is not available.clock_t clock(void)clock returns the processor time used by the program since the beginning ofexecution, or -1 if unavailable. clock()/CLK_PER_SEC is a time in seconds.time_t time(time_t *tp)time returns the current calendar time or -1 if the time is not available. If tp is notNULL, the return value is also assigned to *tp.double difftime(time_t time2, time_t time1)difftime returns time2-time1 expressed in seconds.time_t mktime(struct tm *tp)mktime converts the local time in the structure *tp into calendar time in the samerepresentation used by time. The components will have values in the ranges shown.mktime returns the calendar time or -1 if it cannot be represented.The next four functions return pointers to static objects that may be overwritten by other calls.char asctime(const struct tm tp)234asctime</tt< converts the time in the structure *tp into a string ofthe formSun Jan 3 15:14:13 1988\n\0char ctime(const time_t tp)ctime converts the calendar time *tp to local time; it is equivalenttoasctime(localtime(tp))struct tm gmtime(const time_t tp)gmtime converts the calendar time *tp into Coordinated Universal Time(UTC). It returns NULL if UTC is not available. The name gmtime hashistorical significance.struct tm localtime(const time_t tp)localtime converts the calendar time *tp into local time.size_t strftime(char s, size_t smax, const char fmt, const struct tm *tp)strftime formats date and time information from *tp into s accordingto fmt, which is analogous to a printf format. Ordinary characters(including the terminating '\0') are copied into s. Each %c isreplaced as described below, using values appropriate for the localenvironment. No more than smax characters are placed into s. strftimereturns the number of characters, excluding the '\0', or zero if morethan smax characters were produced.%a abbreviated weekday name.%A full weekday name.%b abbreviated month name.%B full month name.%c local date and time representation.%d day of the month (01-31).%H hour (24-hour clock) (00-23).%I hour (12-hour clock) (01-12).%j day of the year (001-366).%m month (01-12).%M minute (00-59).%p local equivalent of AM or PM.%S second (00-61).%U week number of the year (Sunday as 1st day of week) (00-53).%w weekday (0-6, Sunday is 0).%W week number of the year (Monday as 1st day of week) (00-53).%x local date representation.%X local time representation.%y year without century (00-99).%Y year with century.%Z time zone name, if any.%% %
B.11 Implementation-defined Limits:<limits.h> and <float.h>
The header <limits.h> defines constants for the sizes of integral types.The values below are acceptable minimum magnitudes; larger values may beused.CHAR_BIT 8 bits in a charCHAR_MAX UCHAR_MAX or SCHAR_MAX maximum value of charCHAR_MIN 0 or SCHAR_MIN maximum value of charINT_MAX 32767 maximum value of intINT_MIN -32767 minimum value of intLONG_MAX 2147483647 maximum value of longLONG_MIN -2147483647 minimum value of longSCHAR_MAX +127 maximum value of signed charSCHAR_MIN -127 minimum value of signed charSHRT_MAX +32767 maximum value of shortSHRT_MIN -32767 minimum value of shortUCHAR_MAX 255 maximum value of unsigned charUINT_MAX 65535 maximum value of unsigned intULONG_MAX 4294967295 maximum value of unsigned longUSHRT_MAX 65535 maximum value of unsigned shortThe names in the table below, a subset of <float.h>, are constants relatedto floating-point arithmetic. When a value is given, it represents theminimum magnitude for the corresponding quantity. Each implementationdefines appropriate values.FLT_RADIX 2 radix of exponent, representation, e.g., 2, 16FLT_ROUNDS floating-point rounding mode for additionFLT_DIG 6 decimal digits of precisionFLT_EPSILON 1E-5 smallest number x such that 1.0+x != 1.0FLT_MANT_DIG number of base FLT_RADIX in mantissaFLT_MAX 1E+37 maximum floating-point numberFLT_MAX_EXP maximum n such that FLT_RADIXn-1 is representableFLT_MIN 1E-37 minimum normalized floating-point numberFLT_MIN_EXP minimum n such that 10n is a normalized numberDBL_DIG 10 decimal digits of precisionDBL_EPSILON 1E-9 smallest number x such that 1.0+x != 1.0DBL_MANT_DIG number of base FLT_RADIX in mantissaDBL_MAX 1E+37 maximum double floating-point numberDBL_MAX_EXP maximum n such that FLT_RADIXn-1 is representableDBL_MIN 1E-37 minimum normalized double floating-point numberDBL_MIN_EXP minimum n such that 10n is a normalized number
B.8 Non-local Jumps: <setjmp.h>
The decla rations in <setjmp.h> provide a way to avoid the normal function call and returnsequence, typically to permit an immediate return from a deeply nested function call.int setjmp(jmp_buf env)The macro setjmp saves state information in env for use by longjmp. The return iszero from a direct call of setjmp, and non-zero from a subsequent call of longjmp. Acall to setjmp can only occur in certain contexts, basically the test of if, switch, andloops, and only in simple relational expressions.if (setjmp(env) == 0)/ get here on direct call /else/ get here by calling longjmp /void longjmp(jmp_buf env, int val)longjmp restores the state saved by the most recent call to setjmp, using theinformation saved in env, and execution resumes as if the setjmp function had justexecuted and returned the non-zero value val. The function containing the setjmpmust not have terminated. Accessible objects have the values they had at the timelongjmp was called, except that non-volatile automatic variables
B.7 Variable Argument Lists: <stdarg.h>
The header <stdarg.h> provides facilities for stepping through a list of function argumentsof unknown number and type.Suppose lastarg is the last named parameter of a function f with a variable number ofarguments. Then declare within f a variable of type va_list that will point to each argumentin turn:va_list ap;ap must be initialized once with the macro va_start before any unnamed argument isaccessed:va_start(va_list ap, lastarg);Thereafter, each execution of the macro va_arg will produce a value that has the type andvalue of the next unnamed argument, and will also modify ap so the next use of va_argreturns the next argument:type va_arg(va_list ap, type);The macrovoid va_end(va_list ap);must be called once after the arguments have been processed but before f is exited