0% found this document useful (0 votes)
7 views

ExamAppendix

The document outlines C operator precedence and associativity, detailing the order of operations from highest to lowest. It also provides an overview of the C standard library, including function declarations, types, and macros, as well as file operations and formatted input/output functions. Key aspects include how to open, read, and write files, along with the syntax for formatted output and input functions.

Uploaded by

nataliavromov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
7 views

ExamAppendix

The document outlines C operator precedence and associativity, detailing the order of operations from highest to lowest. It also provides an overview of the C standard library, including function declarations, types, and macros, as well as file operations and formatted input/output functions. Key aspects include how to open, read, and write files, along with the syntax for formatted output and input functions.

Uploaded by

nataliavromov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 13
ahaa ae ae | rage. ori C Operator Precedence and Associativity This page lists all C operators in order of their precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied, Operator Description Associativity | (Parentheses (grouping) Teft-to-ight 0 [Brackets (array subscript) os . [Member selection via object name =>___|Member selection via pointer ++ == lUnary preincrement/predecrement right-to-left + = [Unary plus/minus ! +» TUnary logical negation/bitwise complement (type) |Unary cast (change type) [Dereference & Address sizeot [Determine size in bytes * 7% |Multplication/division/modulus left-to-right += |Addition/subtraction left-to-right <<__>> _[Bitwise shift left, Bitwise shift right left-to-right < <= [Relational Jess than/less then or equal to [ left-to-right > >= _ [Relational greater than/greater than or equal to {= [Relational is equal to/is not equal to [tefi-to-right & [Bitwise AND lef-to-right_| * Bitwise exclusive OR left-to-right i Bitwise inclusive OR ; left-to-right 86 [Logical AND left-to-right 11 [Logical OR left-to-right 2 [Ternary conditional right-to-left = [Assignment right-to-left += == |Addition/subtraction assignment += /= | Multiplication/division assignment $= = |Modulus/bitwise AND assignment “= |= |Bitwise exclusive/inclusive OR assignment <<=_>>=_|Bitwise shift left/right assignment ’ Comma (separate expressions) left-to-right Updated: 02.09,2005, http://www. diftanco.net/cop2220/op-prec. htm 30-10-2006 Appendix B - Standard Library This appendix is a summary of the library defined by the ANSI standard, The standard library is not part of the C language proper, but an environment that supports standard C will provide the function declarations and type and macro definitions of this library, We have omitted a few functions that are of limited utility or easily synthesized from others; we have omitted multi-byte characters, and we have omitted discussion of locale issues; that is, properties that depend on local language, nationality, or culture. ‘The functions, types and macros of the standard library are declared in standard headers: sassert-h> sermo.h> Headers may be included in any order and any number of times, A header must be included outside of any external declaration or definition and before any use of anything it declares. A header need not be a source file, External identifiers that begin with an underscore are reserved for use by the library, as aré all other identifiers that begin with an underscore and an upper-case letter or another underscore. B.1 Input and Output: The input and ouput functions, types, and macros defined in cataio. n> represent nearly one third of the library, A stream is a source or destination of data that may be associated with a disk or other peripheral. 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 or more characters and is terminated by * \n'. An environment may need to convert a text stream to or from some other Tepresentation (such as mapping '\n' to carriage return and linefeed). A binary stream is.a sequence ‘of unprocessed bytes that record internal: deta, with the property that 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 closing the stream. Opening a file returns a pointer to an object of type Fre, which records whatever information is necessary to control the stream. We will use file pointer" and "stream" interchangeably when there is no ambiguity, ‘When a programm begins execution, the three streams stain, stdout, and stdery are already open, Appendix B - Standard Library i itll B.1.1 File Operations The following functions deal with operations on files, The type size_t is the unsigned integral type produced by the si zeof operator. FILE *fopen(const char *filename, const char *mode) fopen opens the named file, and retums.a stream, or NULL if the ‘attempt fails. Legal vahies for mode include: "=" 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 "rs" open text file for update (i.e., reading and writing) "w+" create text file for update, discard previous contents if any append; open or create text file for update, writing at end Update mode permits reading and writing the same file; #£1ush or a file-positioning function must be called between a read and a write or vice versa. If the mode includes » after the initial letter, ag in "rb" or *web*, that indicates a binary file, Filenames are limited to FILENAMB_NAX characters, At most FOPEN_MAX files may be open at once. FILE *freopen(const char “filename, const char *mode, FILE *stri ) freopen opens the file with the specified mode and associates the stream with it. It returns stream, or NULL if an erfor occurs, #reopen is normally used to change the files associated with stdin, stdout, or atderr, i int €flush(FILE *stream) On an output stream, £#1ush causes any buffered but unwritten date to.be written; on an input stream, the effect is undefined. It retums EoF for a write error, and zero otherwise, flush (vuLL) flushes all output streams, int fclose (FILE *stream) tclose flushes any unwritten data for stzean, discerds any unread buffered input, frees eny automatically allocated buffer, then closes the stream. It returns E0F if any errors occurred, and zero otherwise. int remove(const char *filename) remove removes the named file, so that a subsequent attempt to open it will fail. It retums non zero if the attempt fails. » ant rename(const,.char *oldname, const char *newname) ‘xename changes the name of a file; it returns non-zero if the attempt fails. PILE *tmpfile (void) tmpfile creates a temporary file of mode "wh+" that will be automatically removed when closed or when the program terminates normally. tmpfile returns a stream, or NULL 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 a pointer to an intemal static array, tmpnam(s) stores the string in » as well as returning it as the function ages of 17 Value; s must have room for at least 1_tmpnam characters. tmpnam generates a different name each time it is called; at most Twp_wax different names are guaranteed during execution of the program, Note that tmpnam creates a name, not a file. . int setvbuf (FILE vetrean, char *buf, int mode, size_t size) Setvbu controls buffering for the stream, it must be called before reading, writing or any other operation. A mode of _TOFBF causes full buffering, _10LBF line: buffering of text files, and _IONBF no buffering, If but is not ‘NULL, it will be used as the buffer, otherwise a buffer will be allocated. size determines the buffer size, set vbut returns non-zero for any error, void setbuf (PILE *stream, char *buf) If but is NULL, buffering is tuned off for the stream. Otherwise, setbut is equivalent to (void) setvbuf (stream, buf, _roFsP, BUFSzz). B.1.2 Formatted Output The printé functions provide formatted output conversion. int fprinté (FILE ‘stream, const char *format, ...) fprinté converts and writes output to stream under the control of format, The return value is the number of characters written, or negative if an error occurred, ZThe format sting contains two types of objects: ordinary characters, which are copied to the output stveam, and eonversion specifications, each of which causes conversion and printing of the next Suctessive argument to fprintt, Each conversion specification begins with are character ¥ and ends with @ conversion character, Between the ¥ and the conversion character thane may be; in order: +. Flags (in any order), which modify the specification: 9 = which specifies left adjustment of the converted argument in its field, & * which specifies that the mumber will always be printed with a sign, © space: ifthe frst character is not a sign, a space will be prefixed, 2: for numeric conversions, specifies padding to the field width with leading zeros. © & which specifies en altemate output form. For o, the frst digit wll become sere For x Shady a0, OX Will be prefixed to a non-zero result. Fore, 8, £, and G, the output will always have a decimal point; for and «, trailing zeros will not be removed. field width. The converted argument will be printed in a field at least this wide, and wider if necessary, Ifthe converted argument has fees characters than the field width it will be padded on the ef (or right, if left adjustment has bees Tequested) to rake up the field width, The padding character is normally space, bt is sf tre eo padding flag is present, A period, which separates the field width from the precision, A number, the precision, that specifies the maximum number of characters to be printed from A sting, or the mumber of digits to be printed after the decimal point for e ce conversions, oF the number of significant digits for g or @ conversion, or the umber of digits to be printed for an integer (leading os will be added to make up the necessary width), A length modifier h, 2 (letter ell), or u, "*h" indicates that the corresponding argument is to be Printed asa short or unsigned short; "2" indicates that the argument ie @ ong or unsigned long, ““L" indicates that the argument is along double, > E z g 3 s & g z 2 Nidth or precision or both may be specified as +, in which case the value is computed by converting the next argument(s), which must be int, Appendix B - Standard Library Page 4 of 17 ‘The conversion characters and their meanings are shown in Table B.1, If the character after the ¥ is not a conversion character, the behavior is undefined. * Table B.1 Printf Conversions DS .-- 1a Argument type; Printed As int; signed decimal notation. [int; unsigned octal notation (without a leading zero). fansigned ine; unsigned hexadecimal notation (without a leading 0x or 0x), using labcdef for 0x or ABCDEF for 0x. det foc 5 pe nee Se ——— — fe [szc5 unsigned decimal notation. pout ——— le ~ Jane; single character, after conversion fo unsigned char [chax *; characters from the string are printed until a *\o" is reached or until the lnumber of characters indicated by the precision have been printed oe be ‘decimal notation of the form [-]mmm.ddd, where the number of a's is given nn. The default precision is 6; a precision of 0 suppresses the decimal Lee — ne E ; decimal notation of the form (-Im.ddddddes/-xx or (=) m.dddddds,/-x%, yhere the number of d's is specified by the precision. The default precision is ecision of O suppresses 1¢ decimal point. [acuble; ¥e or ¥E is used if the exponent is less than ~4 or greater than or equal to the “| ls.¢ lprecision; otherwise 4 is used. Trailing zeros and a trailing decimal point are not rinted. lvoia +; print as a pointer (implementation-dependent representation). fine +; the number of characters written so far by this call to print is written into the argument. No argument is converted. a i fro argument is converted; print a % int printf (const char *format, ...) ; printf (...) is equivalent to fprintf(stdout, . int sprintf(char *s, const char *format, ...) sprinté is the same as print except that the output is written into the string », terminated with *\o", » must be big enough to hold the result. The return count does not include the "\or, int vprinté (const char *format, va_list arg) int vfprintg (FILE *stream, const char *format, va_list arg) int veprintf (char *8, const char *format, va_list arg) ‘The functions vprinté, vfprinté, and veprintf are equivalent to the corresponding printt functions, except that the variable argument list is replaced by arg, which has been initialized by the va_start macro and perhaps va_arg calls. Sec the discussion of in Section B.7. B.1.3 Formatted Input ‘The scanf function deals with formatted input conversion. int fecanf (FILE ‘stream, const char ‘format, ...) fecant reads from stream under control of format, and assigns converted values through subsequent arguments, each of which must be a pointer. It retums when foxmat is exhausted. fecant returns BoP if end of file or an error occurs before any conversion; otherwise it retums the number of input items converted and assigned. ‘The format string usually contains conversion specifications, which are used to direct interpretation of input, The format string may contain: Blanks or tabs, which are not ignored. © Ordinary characters (not %), which are expected to match the next non-white space character of the input stream + Conversion specifications, consisting of a ¥, an optional assignment suppression character v, an optional number specifying a maximum field width, an optional h, 1, or indicating the width of the target, and a conversion character. A conversion specification determines the conversion of the next input field. Normally the result is placed in the variable pointed to by the corresponding argument. If assignment suppression is indicated by *, as in ¥*a, however, the input field is simply skipped; no assignment is made, An input field is defined as a string of non-white space characters; it extends either to the next white Space character or until the field width, if specified, is exhausted, This implies that scanf will read across line boundaries to find its input, since newlines are white space. (White space characters are blank, tab, newline, carriage return, vertical tab, and formfeed.) ‘The conversion character indicates the interpretation of the input field. The corresponding argument must be a pointer. The legal conversion characters are shown in Table B.2. ‘The conversion characters 4, i, n, o,.u, and x may be preceded by h if the argument is a pointer to short rather than int, or by 2 (letter ell) if the argument is a pointer to long. The conversion characters e, #, and g may be preceded by 2 if a pointer to-doubie rather than float is in the argument list, and by 4 if a pointer to along double, Table B.2 Scanf Conversions [Character] Input Dataj Argument type = a _| a [decimal integer, int me Brea int*, The integer may be in ootal (leading 0) or hexadecimal (leading ox or ox), lo octal integer (with or without leading Zer0); ine 5 | lu. junsigned decimal integer, unsigned int *, —— = ao fx J[nexadecimmal integer (with or without leading ox or 0x); int. _] characters; chaz. The next input characters are placed in the indlcated array, up to the laumber given by the width field; the default is 1. No '\o' is added, The normal skip jover white space characters is suppressed in this case; to read the next non-white space |character, use t28, = lstring of non-white space characters (not quoted); char *, Pointing to an array of (characters large enough to hold the string and a terminating '\o" thet will be added, {floating-point number; float +, The input format for f1oat's is an optional sign, a le.t.g istring of numbers possibly containing a decimal point, and an optional exponent field icontaining an # or e followed by a possibly signed integer. IP ointer value as printed by printé ("¥p" Ji, void +. Appendix B - Standard Library vageoorl/ =» lwrites into the argument the number of characters read so fer by this call; int *, No linput is read. The converted item count is not incremented. fratches the longest non-empty string of input characters from the set between braces; lchar_*. A '\0' is added. (1...) includes ] in the set. [+.,.) __ |fiatehes the longest non-empty string of input characters nor from the set between “**) _Horackets; char +. A '\o! is added. (*) ,..1 includes }.in the set, int scanf(const char ‘format, ...) scant (...) is identical to fecanf (stdin, ...), int sscanf(const char *s, const char *format, } sscanf(s, ...) is equivalent to scent...) except that the input characters are taken from the string B.14 Character Input and Output Functions int fgetc(FILE *stream) fgete returns the next cheracter of stream as an unsigned chax (converted to an int), or zor if end of file or error occurs, char *fgets(char *s, int n, PILE *stream) fgete reads at most the next n-2 characters into the array s, stopping ifa newline is encountered; the newline is included in the array, which is terminated by '\o". fgets retums 8, or NULL if end of file or error occurs. int fpute(int c, FILE *stream) ‘pute writes the character ¢ (converted to an unsigend char) on stream, It returns the character written, or BoP for error. imt fputs(const char *s, FILE *stream) fputs writes the string » (which need not contain \n) on stream; it retums non-negative, or BOF for an error. int getc (FILE *stream) getc is equivalent to fgete except that if it is a macro, it may evaluate stream more than once. int getchar (void) getchar is equivalent to getc (stdin). char *gets (char *s) gets reads the next input line into the array w; it replaces the terminating newline with *\o". It retums 8, or MULL if end of file or error occurs. int pute (int ¢, FILE *strean) pute is equivalent to fpute except that if it is a macro, it may evaluate stream more than once, dnt putchar (int c) putchar (c) is equivalent to pute (ce, stdout), int pute(const char *s) puts writes the string s and a newline to stdout. It returns EOF if an error occurs, non- negative otherwise. 3 int ungete(int c, FILE *stream) ungete pushes ¢ (converted to an unsigned char) back onto stream, where it will be retumed on the next read. Only one character of pushback per stream is guaranteed. EoF may not be pushed back. ungatc retums the character pushed back, or EOP for error, 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, fread retums the number of objects read; this may be less than the number requested, feof and ferror must be used to determine status, size_t fwrite(const void *ptr, size_t size, size_t nobj, PILE ‘stream fwrite writes, from the array ptx, nobj objects of size eize on stream, It returns the number of objects written, which is Jess than nobj on error, B.1.6 File Positioning Functions int £ (FILE ‘stream, long offset, int origin) seek sets the file position for stream; a subsequent read or write will access data beginning at the new position: For a binary file, the position is set to offset characters from origin, which may be sezx_se7 (beginning), SEEx_cur (current position), or SEEX_END (end of file). For a text stream, offset must be zero, or a value returned by #te1 (in which case origin must be SEEK_SET). {seek retums non-zero on error. long ftell(FILE *stream) £te22 retums the current file position for stream, or =1 on error. void rewind (FILE *stream) rewind (fp) is equivalent to fseek(£p, OL, SkEK_SET); cle: ‘err (fp), int fgetpos (FILE *stream, fpos_t *ptr) fgetpos records the current position in stream in *pts, for subsequent use by feetpos, The type fpos_t is suitable for recording such values. fgetpos retums non-zero on error. int fsetpos (FILE *stream, const fpos_t *ptr) -fsetpos positions stream at the position recorded by fgetpos in +ptr. fsetpos retums 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, These indicators may be set and tested explicitly, In addition, the integer expression errno (declared in serzno. h>) may contain an error number that gives further information about the most recent error, void clearerr(FILE *stream) clearer clears the end of file and error indicators for stream, Appendix B - Standard Library Page 8 of 17 int feof (FILE *stream) feof returns non-zero if the end of file indicator for stream is set. int ferror (FILE *stream) ferror retums non-zero if the error indicator for stream is set. void perror(const char *s) persor (s) prints’ and an implementation-defined error message corresponding to the integer in errno, as ifby fprintf(stderr, "ts: %s\n", 8, “error message"); See strerror in Section B.3. B.2 Character Class Tests: The header declares flmctions for testing characters. For each function, the argument list is an int, whose value must be ZOF or representable as an unsigned char, and the return value is an int, The fimetions return non-zero (true) if the argument c satisfies the condition described, and zero ifnot. isalnum(c) isaipha(c) or {edigit(c) is true asalpha(c)* isupper(c) or islower (c) is true. ascntrl(c) . control character isdigit (ce) ° decimal digit dsgraph(c) - printing character except space islower(c) lower-case letter dsprint (c) printing character including space dspunct (c) printing character except space or letter or digit isspace(c) space, formfeed, newline, carriage return, tab, vertical tab supper (c) upper-case letter ‘ isxdigit (c) hexadecimal digit In the seven-bit ASCII character set, the printing characters are,0x20 ( ') toox7E ('~"); the control characters are 0 UL to oxuF (US), and.ox7" (DEL), In addition, there are two functions that convert the case of letters: dnt tolower(c) convert c to lower case int toupper(c) convert eto upper case If c is an upper-case letter, tolower (c) returns the corresponding lower-case letter, toupper (c) retums the corresponding upper-case letter; otherwise it retums c. B.3 String Functions: There are two groups of string functions defined in the header . The first have names beginning with st; the second have names beginning with mem, Except for menmove, the behavior is undefined if copying takes place between overlapping objects. Comparison functions treat arguments as unsigned char amays. In the following table, variables s and t are of type char +; cs’and ct are Oftype const char +; n is of type size_t; and cis an dnt converted to char. char *strepy (s,ct) char *stencpy copy at most n characters of string ct to 8; retin », Pad with '\o''sifct has (s,ct,n) fewer than n characters. char *streat copy string ct to string », including '\ 0"; retum s. ; concatenate string ct to end of string @; retum's. (s, et) char *stxncat concatenate at most n characters of string ct to string s, terminate s with (s,ct,n) "\o"; retum s. ine strenpi(ce,ce) compare sting eo string ct, retim <0 if eecet, Oifcneet, orf pet, int strnomp compare at most n characters of string cs to string ct; return <0 if csect, Oif (es, ct,n) esnact, or >0 if ceoct. Cr TSP retum pointer to first occurrence of « in os or NULL if not present, fee) T'™* return pointer to last occurrence of e in e8 or NULL if not present. (earn) return length of prefix of ea consisting of characters in ct. feerae) TPP? return length of prefix of ce consisting of characters not in dt, char *atrpbrk return pointer to first occurrence in string os of any character string ct, or {es, ct) NULL if not present. char ‘strstr {e, ct} return pointer to first occurrence of string ct in cs, or. NULL if not present. size_t strien(cs) retum length of cs. char *strerror(n) retum pointer to implementation-defined string corresponding to error n. char *atrtok (s,ct) strtok searches s for tokens delimited by characters from ct; see belaw. A sequence of calls of strtok (s, ct) splits » into tokens, each delimited by a character from et, The first call in a sequence has anon-NULL «, it finds the first token in » consisting of characters not in ot; it terminates that by overwriting the next character of s with '\o' and retums a pointer to the token, Bach subsequent call, indicated by a NULL value of a, returns the next such token, searching from just past the end of the previous one. strtok retums NULL When no further token is found. The string ct may be different on each call. Themen. .. fictions are meant for manipulating objects as character arrays; the intent is an interface to efficient routines. In the following table, » and ¢ are of type void +; cs and ct are of" type const void *; nis of type size_t; and c is an int converted to an unsigned char, void *memepy 3 copy n characters from ct toe, and retum s, Eig eRIMOV® same as memepy except that it works even if the objects overlap, ait compare the first n characters of ca with ct; retum as with stromp, void *memchr return pointer to first occurrence of character c in cs, or NULL if not present (es,¢,n) among the first n characters, void *memset Pet) place character c into first n characters of s, return s. * B.4 Mathematical Functions: ‘The header declares mathematical functions and macros.. ‘The macros EDOM and ERANGE (found in ) are non-zero integral constants that are used to signal domain and range errors for the functions; #UGE_VAL is a positive double value, A domain error occurs if an argument is outside the domain over which the function is defined, On a domain error, exrno 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 the result overflows, the function returns HUGE_VAL with the right sign, and exrno is set to ERANGE, If the result underflows, the function retums zero; whether errno is set to ERANGE is implementation-defined. In the following table, x and y are of type double, n is an int, and all functions retum double, Angles for trigonometric fimctions are expressed in radians. sin (x) sine of x cos (x) cosine of x tan (x) tangent of x asin (x) sin-1(x) in range [-pi/2,pi/2), x in [-1,1]. acos (x) cos"l(x) in range [0,pi), x in (-1,1]. atan (x) tan-1(x) in range [-pi/2,pi/2]. atan2(y,x) — tan-l(y/x) in range [-pi,pi). sinh (x) hyperbolic sine of x cosh (x) hyperbolic cosine of x tanh (x) hyperbolic tangent of x exp (x) exponential function ¢* Log (x) natural logarithm In(x), 2>0. Logo (x) base 10 logarithm log, q(x), x0. pow(x,y) 2”, A domain error occurs if x=0 and y<=0, or if x<0 and y is not an integer. 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| Adexp(x,n) — x#2n frexp(x, int splits x into a normalized fraction in the interval [1/2,1) which is returned, and a *ip) power of 2, which is stored in *exp. Ifx is zero, both parts of the result are zero. modé (x, splits x into integral and fractional parts, each with the same sign as x, It stores the double *4p) integral part in +p, and returns the fractional part. floating-point remainider of x/y, with the same sign as x. If y is zero, the result is implementation-defined, £mod (x,y) B.5 Utility Functions: The header declares functions for number conversion, storage allocation, and similar 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 # to int; it is equivalent to (int)strtol(s, (char**)NULL, 10), long atol (const char +s) converts s to ong; it is equivalent to strtol ( (char**)NULL, 10). double strtod(const char *s, char **endp) strtod converts the prefix of » to double, ignoring leading white space; it stores a pointer to any unconverted suffix in *endp unless endp is NULL. If the answer would overflow, #uGE_VAL is retumed.with the proper sign; if the answer would underflow, zero is returned, In either case exrno is set to BRANGE. long strtol(const char *s, char **endp, int base) strtol converts the prefix of s to long, ignoring leading white space; it stores a pointer to any unconverted suffix in *endp unless endp is NULL, If base is between 2 and 36, conversion is done assuming that the input is written in that base, If base is zero, the base is 8, 10, or.16; leading 0 implies octal and leading ox or ox hexadecimal. Letters in either case represent digits from 10 to bas Jeading ox or ox is permitted in base 16. If the answer would overflow, LONG_NAX of LONG_MIN is retumed, depending on the sign of the result, and exxno is set to ERANGE, , unsigned long strtoul (const char *s, char **endp, int base) strtoul js the same as stxtol except that the result is unsigned long and the error value is ULONG_MAX, int rand (void) and retums a pseudo-random integer in the range 0 to RAND_MAX, which is at least 32767. void srand(unsigned int a) srand uses seed as the seed for a new sequence of pseudo-random numbers, The initial seed is. void *calloc(size_t nobj, size_t size) calloe retums a pointer to space for an array of nobj objects, each of size size, or MULL if the request cannot be satisfied. The space is initialized to zero bytes. void *malloc (size_t size) malloc retums a pointer to space for an object of size aize, or NULL if the request canriot 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 be unchanged up to the minimum of the old and new sizes, If the new size is larger, the'new space is uninitialized, reaiioc returns a pointer to the new space, or NULL if the request cannot be satisfied, in which case +p is unchanged. void free(void ¥p) Lee ast ae et ee ee ee ae free deallocates the space pointed to by p; it does nothing if p is NULL, p must be a pointer 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 programy'termination, atexiit functions are called in reverse order of registration, open files are flushed, open streams are closed, and control is returned to the environment. How status is returned to the environment is implementation-dependent, but zero is taken as successful termination. The values 8X17_sUCCESS and EXIT_PATLURE may also be used. int atexit (void (*fen) (void) ) atexit registers the function fen 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, system retums non- ‘ zero if there is a command processor. If s is not NULL, the return value is implementation- dependent. char *getenv(const char *name) getenv retums the environment string associated with nane, or NULL if no string exists, Details are implementation-dependent. void’ vbsearch (const void *key, const void “base, size_t n, size_t size, int (temp) (const void *keyval, const void *éatum)) search searches base {0} .. .base(n-2) for an item that matches *key, The function emp must return negative if its first argument (the search key) is less than its second (a table entry), zero if equal, and positive if greater. Items in the array base must be in ascending order. search returns a pointer to a matching item, or NULL if none exists. void qsort (void *base, size_t n, size.t size, int (*emp) (const void *, const void *)) qsort sorts into ascending order an array base [0]... .base(n-1) of objects of size size. The comparison function omp is as in baeaxch, dnt abs (int n) ‘abs returns the absolute value ofits int argument. Jong labs (long n) ‘Labs returns the absolute value of its long argument. div_t @iv(int, num, int denom) diy computes the quotient and remainder of num/denom. The results are stored in the int members quot arid reni of a structure of type div_t. Adiv_t Idiv(leng num, long denom) idiv computes the quotient and remainder of num/denom. The results are stored in the long members quot and rem of a structure of type 14iv_t.

You might also like