The root of all modern languages is ALGOL, introduced in the early 1960s. ALGOL was the first computer language to use a block structure. Although it never becaming populer in USA, it was widely used in Europe. ALGOL gave the concept of structured programming to the computer science community. Computer scientists like corrado Bohm, Guiseppe Jacopini and Edsger Dijkstra popularized this concept during 1960s. Subsequently, several language were announced.
In 1967, Martin Richards developed a language called BCPL(Basic Combined Programming Language) Primarilly for writing system software. In 1970, Ken Thompson created a language using many features of BCPL and called it simply B. B was used to create early versions of UNIX operating system at Bell laboratories. Both BCPL and B were "typeless" system programming languages.
Cwas evolved from ALGOL. BCPL and B by Dennis Ritchie at the Bell Laboratories in 1972. C uses many concepts from these languages and added the concept of data types and other powerful features. Since it was developed along with the UNIX operating system. It is strongly associated with UNIX. This operating system, which was also developed at Bell laboratories, was coded almost entirely in C. UNIX is one of the most popular network operating systems in use today and the heart of the internet data superhighway.
For many years, C was used mainly in academic environments. but eventually with the relese of many C compilers for commercial use and the increasing popularity of UNIX, it began to gain widespread support among computer professionals. Today, C is running under a variety of operating system and hardware platforms.
During 1970s, C had evolved into what is now known as traditional c". the language became more popular after publication of the book "The C Programming Language" by Brian Kerningham and Dennis Ritchie in 1978. The rapid growth of C led to the development of different versions of the language that were similar but often incompatible. This posed a serious problem for system developers to assure that the C language remains standard. In 1983, American National Standards Institute(ANSI) appointed a technical comittee to define a standard for C. The committee approved a version of C in December 1989 which is now known as ANSI C. It was then approved by the International Standards Organization(ISO) in 1990. The version of c is also referred to as c89.
Then, c make changes with other language(c++,java) behavior. This version is usually referred to as C99.
With assert you can test your programm for logical errors.
The assert () macro will insert diagnostics into programs
When executed, if expression (which is a scalar type you have) is false (ie, compares equal to 0),
assert (), provide information about the particular call that failed to stderr and abort ()
Reads a string from the console.
cgets reads a string of characters from the console and stores the string (and the string length) in the location pointed to by str.
cgets reads as long as a sign to mark the combination carriage return / line feed (CR / LF) occurs or the maximum number of characters has been read. When reading cgets the CR / LF combination is replaced by the combination of characters \ 0 (null terminator) before the string is stored.
Assign str[0] before calling cgets to the maximum length of the string to be read.
After completion of the read operation st is assigned[1] the actual number of characters read.
The reading begins with the character at position str[2] and ends with the null terminator.
Consequently, at least str str[0] in length plus 2 bytes.
return value: a pointer to str[2]
clreol
clrscr
Calculate the Complex Arc Hyperbolic Cosine
clears the screen and move the cursor to upper left corner of the screen.
cprintf
prints formatted output to the screen.
cprintf takes multiple arguments, applies to each of the format specifier contained in the format string, pointed to by
format, and prints the formatted data directly to the current text window on the screen. The number of available format
must match the number of arguments.
For more information on format specifiers, see printf format”.
Depending _directvideo of the global variable, the string is written either directly or through a BIOS call to screen memory.
To contrast to fprintf and printf, not translated cprintf line character (\ n) in the combination of characters carriage
return / line feed (\ r \ n). Tab character (specified with t \) are not expanded to spaces.
cputs
Returns a string to the screen.
cputs is the null-terminated string from str in the current text window. The newline character is not here appended to the string.
Depending _directvideo of the global variable, the string is written either directly or through a BIOS call to screen memory.
To contrast to fprintf and printf, not translated cputs line character (\ n) in the combination of characters carriage return / line feed (\ r \ n).
cscanf
reads input from the console and reformat it.
cscanf reads directly from the console of a series of input fields one character at.
Then each field is formatted according to the format specifier is passed cscanf in the format designated by the pointer format string.
Finally stores cscanf formatted input to the direction indicated by the argument address memory address and shows the input on the screen.
There must be as many format specifiers and addresses given as input fields
delline
delete the line containing the cursor and move all lines below it one line up.
getch
prompts the user to press a character and that character is not printed on screen
getche
Reads a character from the keyboard and display it on the screen.
reads a single character from the keyboard, and there are direct or via a BIOS call made in the current text window.
getpass
reads a password
getpass reads a password from the system console, after the user is prompted for a password to a null-terminated string and display the password has been disabled. A pointer to a null-terminated string of up to eight characters (not counting null terminator) is returned.
gettext
copy text from a text mode window in memory.
stores the text content of the rectangular area of the screen, which is defined by left, top, right and bottom, and also stores it in the storage area pointed to by dst. all coordinates are absolute screen coordinates, not window-based. The top left corner has coordinates (1,1). sequentially reads the contents of the rectangle from the left to right and from top to bottom in the memory. each screen position is represented by 2 bytes in memory: The first byte contains the characters present in the cell, and the second byte contains the graphic attribute of the cell. The memory requirement for a rectangle with a width of w and a height of h columns goals is defined as follows:
bytes = (h line) x (w columns) x 2
returns returns 1 if the operation was successful else 0
gettextinfo
Retrieves information from text-mode.
transfers the current text mode video information into the structure text_info pointed to by r.
available is wintop, winleft, winright, winbottom, attribute, normattr, currmode, screenheight, screenwidth, curx, cury
gotoxy
places cursor at a desired location on screen.
highvideo
Used to select the highlighted character.
selects highlighted character by setting Intensity bits the current foreground color. This function has no effect on the characters that are currently displayed on the screen.
insline
kbhit
used to find ou if a key has been pressed or not
lowvideo
movetext
normvideo
putch
prints characters on the screen.
putch gives the character c to the current text window. It is a text-mode function that displays output directly to the console.
putch replaces the newline character (\ n) characters are not merchandise return / line feed.
Depending _directvideo of the global variable, the string is written either directly or through a BIOS call to screen memory.
Return values: success the character, failure EOF
puttext
textbackground
change of current background color in text mode
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
textcolor
change the color of drawing text where color is a integer variable
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
textmode
ungetch
Pushes a character back into the keyboard buffer.
return
Successful execution ungetch returns the character ch.
If an error occurs, the function returns EOF.
wherex
return current horizontal cursor position
wherey
return current vertival cursor position
window
Defines the active text mode window.
window defines a text window on the screen. If the coordinates are invalid, the call window is ignored. left and top are the screen coordinates of the upper left corner of the window. right, and bottom are the screen coordinates of the lower right corner of the window.
delay function is used to suspend execution of a program for a particular time
the parameter are number of milliseconds ( 1 second = 1000 milliseconds)
getdate
Print current computer system date.
gettime
gettime function is used to find current system time.
returns structure varibale of type ( struct time ).
nosound
turn off the PC speaker.
setdate
change the system date
sleep
delay programm for given number of seconds
sound
Producessound of a specified frequency.
mostly used for adding music to c program
random values and delay needed to make some strange sounds.
The va_arg() macro expands to an expression that has the type and value of the
next argument in the call. The argument ap is the va_list ap initialized by
va_start(). Each call to va_arg() modifies ap so that the next call returns
the next argument. The argument type is a type name specified so that the
type of a pointer to an object that has the specified type can be obtained
simply by adding a * to type.
The first use of the va_arg() macro after that of the va_start() macro returns
the argument after last. Successive invocations return the values of the
remaining arguments.
If there is no next argument, or if type is not compatible with the type of
the actual next argument (as promoted according to the default argument
promotions), random errors will occur.
If ap is passed to a function that uses va_arg(ap,type) then the value of ap
is undefined after the return of that function.
va_copy
An obvious implementation would have a va_list be a pointer to the stack frame
of the variadic function. In such a setup (by far the most common) there
seems nothing against an assignment
va_list aq = ap;
Unfortunately, there are also systems that make it an array of pointers (of
length 1), and there one needs
va_list aq;
*aq = *ap;
Finally, on systems where arguments are passed in registers, it may be
necessary for va_start() to allocate memory, store the arguments there, and
also an indication of which argument is next, so that va_arg() can step
through the list. Now va_end() can free the allocated memory again. To
accommodate this situation, C99 adds a macro va_copy(), so that the above
assignment can be replaced by
va_end
Each invocation of va_start() must be matched by a corresponding invocation of
va_end() in the same function. After the call va_end(ap) the variable ap is
undefined. Multiple traversals of the list, each bracketed by va_start() and
va_end() are possible. va_end() may be a macro or a function.
va_list
va_list is a data type that is used for the macro variable arguments in function calls with any number of arguments to keep the arguments in a list. It is only for the macros va_start (), va_arg, va_end () function.
va_start
The va_start() macro initializes ap for subsequent use by va_arg() and
va_end(), and must be called first.
The argument last is the name of the last argument before the variable
argument list, that is, the last argument of which the calling function knows
the type.
Because the address of this argument may be used in the va_start() macro, it
should not be declared as a register variable, or as a function or an array
type.
The value for BUFSIZ (buffer) should normally be 256 KB, 512 KB or 4096 KB. This depends on the system and the compiler.
clearerr
The clearerr function resets the error flags and EOF indicator for the given stream.
When an error occurs, you can use |perror()| to figure out which error actually occurred.
fclose
Close the current stream / file
Used to close the specified file (stream). You should always use this function, to clean up after using a file.
Any data that has been written to the file, but not actually made it that far yet, i.e. which has only been written to the file buffer in memory,
will then be actually written to the physical file itself by the operating system.
The space in memory allocated for these buffers will also be deallocated. Any user defined buffers (specified by setbuf and setvbuf will however, not be deallocated.
Any temp files associated with the stream will also be deleted.
Returns EOF on error, zero otherwise.
fdopen
fdopen() is the counterpart to fileno(). As a mode, such as the file is opened, the same modes as the can open() can be used.
fdopen() is often applied to file descriptors that are returned from functions that set up the pipes or channels of communication in networks. This is because some functions like open(), dup(), dup2(), fcntl(), pipe(), … in networks can not do anything with streams and require file descriptors. But to again generate descriptors from a stream (FILE pointer), the function fdopen required.
Arguments
Open a file
Arguments for mode are:
“r” Open a file for reading
“w” Create / writing
“a” Append
“b” Open a binary file
“rb” Open binary file for reading
”+” Open file for read/write
“r+” text update (reading and writing)
“w+” text update, discarding previous content (if any)
“a+” text append, reading, and writing at end
example fdopen(“test.txt”, “r+”);, fdopen(“test.txt”, “w+”); fdopen(“test.txt”, “rw”); …
feof
checks that are applied to a stream or data or the end-of-file indicator is set.
Used to determine if the end of the file (stream) specified, has been reached. When a file is being read sequentially one line, or one piece of data at a time (by means of a loop, say), this is the function you check every iteration, to see if the end of the file has come.
Returns non-zero if end-of-file indicator is set for stream stream.
ferror
the function ferror tests the error indicator for the stream pointed to by stream, returning non-zero if it is set. The error indicator can only be reset by the clearerr function. Returns non-zero if error indicator is set for stream stream.
fflush
Flushes stream stream and returns zero on success or EOF on error. Effect undefined for input stream. fflush(NULL) flushes all output streams.
fgetc
Returns next character from (input) stream stream, or EOF on end-of-file or error.
fgetpos
Stores current file position for stream stream in *pos. Returns non-zero on error.
The fgetpos() function stores the file position indicator of the given file stream in the given position variable.
The position variable is of type fpos_t (which is defined in stdio.h) and is an object that can hold every possible position in a FILE.
fgetpos() returns zero upon success, and a non-zero value upon failure.
fgets
Copies characters from (input) stream stream to sstr, stopping when n-1 characters copied, newline copied, end-of-file reached or error occurs. If no error, str is NUL-terminated. Returns NULL on end-of-file or error, str otherwise.
FILE
stream file
fopen
Opens file named restrict path and returns a stream, or NULL on failure. mode may be one of the following for files or one of those strings with b included (after the first character), for binary files.
Arguments
Open a file
Arguments for mode are:
“r” Open a file for reading
“w” Create / writing
“a” Append
“b” Open a binary file
“rb” Open binary file for reading
”+” Open file for read/write
“r+” text update (reading and writing)
“w+” text update, discarding previous content (if any)
“a+” text append, reading, and writing at end
example fopen(“test.txt”, “r+”);, fopen(“test.txt”, “w+”); fopen(“test.txt”, “rw”); …
fpos_t
Object containing information to specify a position within a file This type of object is used to specify a position within a file. An object of this type is capable of specifying uniquely the position within a file.
fprintf
Converts (according to format format) and writes output to stream stream. Number of characters written, or negative value on error, is returned.
optional flag:
- left adjust
+ always sign
0 zero pad
# Alternate form: for conversion character o, first digit will be zero, for [xX], prefix 0x or 0X to non-zero value, for [eEfgG], always decimal point, for [gG] trailing zeros not removed.
optional minimum width: if specified as *, value taken from next argument (which must be int).
optional . (separating width from precision)
optional precision: for conversion character s, maximum characters to be printed from the string, for [eEf], digits after decimal point, for [gG], significant digits, for an integer, minimum number of digits to be printed. If specified as *, value taken from next argument (which must be int).
optional length modifier:
h short or unsigned short
l long or unsigned long
L long double
conversion character:
d,i int argument, printed in signed decimal notation
o int argument, printed in unsigned octal notation
x,X int argument, printed in unsigned hexadecimal notation
u int argument, printed in unsigned decimal notation
c int argument, printed as single character
s char* argument
f double argument, printed with format [-]mmm.ddd
e,E double argument, printed with format [-]m.dddddd(e|E)(+|-)xx
g,G double argument
p void* argument, printed as pointer
n int* argument : the number of characters written to this point is written into argument
% no argument; prints %
fputc
Writes ch, to stream stream. Returns ch, or EOF on error.
fputchar
The fputchar() function writes the character specified by the argument c to the output stream stdout. This function is identical to the putchar() function.
fputs
Writes str, to (output) stream stream. Returns non-negative on success or EOF on error.
fread
fread reads num number of objects from a stream (where each object is size bytes) and places them into the array pointed to by buffer. The return value of the function is the number of read data
freopen
closes file associated with stream, then opens file filename with specified mode and associates it with stream. Returns stream or NULL on error.
fscanf
Performs formatted input conversion, reading from stream stream according to format format. The function returns when format is fully processed. Returns number of items converted and assigned, or EOF if end-of-file or error occurs before any conversion. Each of the arguments following format must be a pointer. Format string may contain:
blanks and tabs, which are ignored
ordinary characters, which are expected to match next non-white-space of input
%
optional assignment suppression character “*”
optional maximum field width
optional target width indicator:
h argument is pointer to short rather than int
l argument is pointer to long rather than int, or double rather than float
L argument is pointer to long double rather than float
conversion character:
d decimal integer; int* parameter required
i integer; int* parameter required; decimal, octal or hex
o octal integer; int* parameter required
u unsigned decimal integer; unsigned int* parameter required
x hexadecimal integer; int* parameter required
c characters; char* parameter required; white-space is not skipped, and NUL-termination is not performed
s string of non-white-space; char* parameter required; string is NUL-terminated
e,f,g floating-point number; float* parameter required
p pointer value; void* parameter required
n chars read so far; int* parameter required
[…] longest non-empty string from specified set; char* parameter required; string is NUL-terminated
[^…] longest non-empty string not from specified set; char* parameter required; string is NUL-terminated
% literal %; no assignment
fseek
Sets file position for stream stream and clears end-of-file indicator. For a binary stream, file position is set to offset bytes from the position indicated by origin: beginning of file for SEEK_SET, current position for SEEK_CUR, or end of file for SEEK_END. Behaviour is similar for a text stream, but offset must be zero or, for SEEK_SET only, a value returned by ftell. Returns non-zero on error.
fsetpos
reset the position indicator to using fsetpos() stores the current file position indicator to the location indicated by the information in pos Returns non-zero on error.
ftell
Returns current file position for stream stream, or -1 on error.
The fwrite() function writes, from the array buffer, count objects of size size to stream. The return value is the number of objects written.
getc
Returns next character from (input) stream stream, or EOF on end-of-file or error.
getchar
Get a character
gets
Copies characters from stdin into str until newline encountered, end-of-file reached, or error occurs. Does not copy newline. NUL-terminates s. Returns str, or NULL on end-of-file or error. Should not be used because of the potential for buffer overflow.
perror
Prints str (if non-null) and strerror(errno) to standard error as would:
printf
The function printf prints format to STDOUT
Code Description
%c character value
%s string of characters
%d signed integer
%i signed integer
%f floating point value
%e scientific notation, with a lowercase “e”
%E scientific notation, with a uppercase “E”
%g use %e or %f
%G use %E or %f
%o octal
%u unsigned integer
%x unsigned hexadecimal, with lowercase letters
%X unsigned hexadecimal, with uppercase letters
%p a pointer
%n the argument shall be a pointer to an integer in which the number of characters written is placed
%% shall be a % sign
\n (newline)
\t (tab)
\v (vertical tab)
\f (new page)
\b (backspace)
\r (carriage return)
putc
put char into a stream.
putchar
put a character into stdout
puts
Writes str (excluding terminating NUL) and a newline to stdout. Returns non-negative on success, EOF on error.
remove
Removes specified file. Returns non-zero on failure.
rename
Changes name of file oldname to newname. Returns non-zero on failure.
rewind
equal like fseek(stream, 0L, SEEK_SET); clearerr(stream); Resets the read pointer to the beginning of the File and clear the error indicator
scanf
The function returns the number of items that were successfully read
EOF if the input stream reached its end, or a negative number if an error occurs.
mostly like printf but for input.
setbuf
Controls buffering for stream stream. For null buf, turns off buffering, otherwise equivalent to (void)setvbuf(stream, buf, _IOFBF, BUFSIZ).
setbuf is deprecated use setvbuf instead
Controls buffering for stream stream. mode is _IOFBF for full buffering, _IOLBF for line buffering, _IONBF for no buffering. Non-null buf specifies buffer of size size to be used; otherwise, a buffer is allocated. Returns non-zero on error. Call must be before any other operation on stream.
_IOLBF File will buffered line by line
_IONBF Input/Output will not be buffered
_IOFBF Input/Output will fully buffered
snprintf
The function snprintf() format the format specified by arguments of the printf format specification and writes the result to the specified string by dest. size specifies the maximum length of the string at least. The string in least receive in any case a terminating NULL character. In no case is dest [destsize - 1] also written.
The return value is the number of characters that would have been written if the string would be least long enough.
To avoid buffer overflows, use this function over strcat strcpy, strncpy and strncat are preferred, since it is costly for the latter functions to be held on the remaining available space in the string Array.
sscanf
sscanf reads formatted input text from the string addressed by source .
No file input is performed. Following the format in the argument list may be one or more additional pointers addressing storage where the input values are stored.
The string pointed to by format is in the same form as that used by fscanf.
Refer to the fscanf description for detailed information concerning the formatting conventions.
tmpfile
Creates temporary file which will be removed when closed or on normal program termination.
standard mode (mode “wb+”)
Returns stream or NULL on failure.
tmpnam
Assigns to s (if s non-null) and returns unique name for a temporary file. Unique name is returned for each of the first TMP_MAX invocations.
ungetc
Pushes chr (which must not be EOF), onto (input) stream stream such that it will be returned by the next read. Only one character of pushback is guaranteed (for each stream). Returns chr, or EOF on error.
vfprintf
Equivalent to fprintf with variable argument list replaced by arg, which must have been initialised by the va_start macro (and may have been used in calls to va_arg).
vfscanf
The vscanf(), vfscanf(), and vsscanf() functions shall be equivalent to the scanf(), fscanf(), and sscanf() functions, respectively, except that instead of being called with a variable number of arguments, they are called with an argument list as defined in the header. These functions shall not invoke the va_end macro. As these functions invoke the va_arg macro, the value of ap after the return is unspecified.
vprintf
Equivalent to printf with variable argument list replaced by arg, which must have been initialised by the va_start macro (and may have been used in calls to va_arg).
is used to generate a string from a format string and then print to standard output stdout. vprintf can understood as a combination of puts and vsprintf.
vscanf
The functions vscanf(), vfscanf(), and vsscanf() are functionally equivalent to scanf(), fscanf(), and sscanf(), respectively, except that the argument list has been replaced by a pointer to a list of arguments. This pointer must be of type va_list, which is defined in the header .
vsprintf
generate a string from a format string. For this purpose, the buffer that is passed as first argument, the format string is copied and replaces the substitution symbol with the given parameters.
vsscanf
The vscanf(), vfscanf(), and vsscanf() functions shall be equivalent to the scanf(), fscanf(), and sscanf() functions, respectively, except that instead of being called with a variable number of arguments, they are called with an argument list as defined in the header. These functions shall not invoke the va_end macro. As these functions invoke the va_arg macro, the value of ap after the return is unspecified.
The atof() function converts the initial portion of the string pointed to by
nptr to double. The behavior is the same as
strtod(nptr, (char **) NULL);
except that atof() does not detect errors.
atoi
convert a string to integer
atol
convert a string to long integer.
strtod
strtod converts a string into a double variable.
strtol
strtol Converting a string to an long integer
str: the string to be converted
endptr: address of a pointer variable that points to the last character read, so the character that is not owned by a number
base: base between 2 and 36
Be found unprefixed numbers, these numbers in base 10 are accepted.
If the base '0 'is specified, the strings make a reference to the basis used
(leading “0x” for hexadecimal, “0” for octal, numbers).
strtoul
strtoul Converting a string to an unsigned long integer
str: the string to be converted
endptr: address of a pointer variable that points to the last character read, so the character that is not owned by a number
base: base between 2 and 36
Be found unprefixed numbers, these numbers in base 10 are accepted.
If the base '0 'is specified, the strings make a reference to the basis used
(leading “0x” for hexadecimal, “0” for octal, numbers).
Mathematical functions:
abs
computes the absolute value of the integer i
labs
computes the absolute value of a long integer
returns the absolute value of a number
the case of a negative number the sign is reversed, a positive number is returned unchanged.
labs is functionally equivalent to abs (), but uses the data type long int
div
calculates the quotient and remainder from division.
ldiv
calculate the quotient and remainder in integer division (long integer).
Widechar conversions:
wcstombs
wcstombs converts a wide character string into a multibyte character string.
conversion stops after the size n is reached.
The behavior of wcstombs is affected by the LC_CTYPE category of the current locale
str = destination string
pwcs = pointer to wide string
n = chars to convert
wctomb
wctomb converts a wide character to a multibyte character in the string.
wctomb maximum MB_CUR_MAX sign stores in a string.
The behavior of wctomb is affected by the LC_CTYPE category of the current locale.
Multibyte conversions / functions:
mblen
Determines how many bytes are used for a character.
mbstowcs
mbstowcs converts multibyte characters to wide characters
mbtowc
converts a multibyte character into a wide character.
Memory manipulation:
calloc
The calloc() function shall allocate unused space for an array of nelem elements each of whose size in bytes is elsize.
The space shall be initialized to all bits 0.
The order and contiguity of storage allocated by successive calls to calloc() is unspecified.
The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a
pointer to any type of object and then used to access such an object or an array of such objects in the space
allocated (until the space is explicitly freed or reallocated). Each such allocation shall yield a pointer to an object disjoint
from any other object. The pointer returned shall point to the start (lowest byte address) of the allocated space.
If the space cannot be allocated, a null pointer shall be returned. If the size of the space requested is 0, the behavior
is implementation-defined: the value returned shall be either a null pointer or a unique pointer.
return value
Upon successful completion with both nelem and elsize non-zero, calloc() shall return a pointer to the allocated space.
If either nelem or elsize is 0, then either a null pointer or a unique pointer value that can be successfully passed to free() shall be returned.
Otherwise, it shall return a null pointer and set errno to indicate the error.
free
The free() function shall cause the space pointed to by ptr to be deallocated; that is, made available for further allocation.
If ptr is a null pointer, no action shall occur. Otherwise, if the argument does not match a pointer earlier returned by
the calloc(), malloc(), posix_memalign(), realloc(), or strdup() function, or if the space has been deallocated by a call
to free() or realloc(), the behavior is undefined.
Any use of a pointer that refers to freed space results in undefined behavior.
return value
The free() function shall not return a value.
realloc
The realloc() function shall change the size of the memory object pointed to by ptr to the size specified by size.
The contents of the object shall remain unchanged up to the lesser of the new and old sizes.
If the new size of the memory object would require movement of the object, the space for the previous instantiation of the object is freed.
If the new size is larger, the contents of the newly allocated portion of the object are unspecified.
If size is 0 and ptr is not a null pointer, the object pointed to is freed. If the space cannot be allocated, the object shall remain unchanged.
If ptr is a null pointer, realloc() shall be equivalent to malloc() for the specified size.
If ptr does not match a pointer returned earlier by calloc(), malloc(), or realloc() or if
the space has previously been deallocated by a call to free() or realloc(), the behavior is undefined.
The order and contiguity of storage allocated by successive calls to realloc() is unspecified.
The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned
to a pointer to any type of object and then used to access such an object in the space allocated
(until the space is explicitly freed or reallocated). Each such allocation shall yield a pointer to an object disjoint from any other object.
The pointer returned shall point to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned.
return value
Upon successful completion with a size not equal to 0, realloc() shall return a pointer to the (possibly moved) allocated space.
If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned.
If there is not enough available memory, realloc() shall return a null pointer and set errno to [ENOMEM].
malloc
The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is unspecified.
The order and contiguity of storage allocated by successive calls to malloc() is unspecified.
The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer
to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated).
Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points
to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned.
If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer.
return value
RETURN VALUE
Upon successful completion with size not equal to 0, malloc() shall return a pointer to the allocated space.
If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned.
Otherwise, it shall return a null pointer and set errno to indicate the error.
Process control:
abort
Cause abnormal program termination, and try to catch SIGABRT.
no return value
atexit
The atexit function registers the given function to be called at normal
process termination
atexit returns the value 0 if successful, otherwise it returns
a nonzero value.
exit
exit causes the termination of a program.
To the environment in which the program was started, a return code will be sent.
getenv
getenv matches the string pointed to by name
returns a pointer to the value in the environment, or NULL if there is no match.
system
system calls a command on the shell
Random number generation:
rand
Generates a random Number.
srand
srand is used to initialize the random number generator.
The use of date / time to initialize the generator
means that the generated sequence of numbers “random” is.
Operator:
sizeof
sizeof operator returns the number of bytes to be reserved for a variable or a data type.
Array functions:
bsearch
key - The element that is searched for
base - pointer to the first element of the array to be searched
nitems - number of elements in the array
size - size of a single element
compare - comparison function to compare two elements together.
return values:
pointer to an entry in the array that matches the search key.
If key not found, NULL pointer returned.
qsort
base = Pointer to elements
nitems = Number of elements
size = Size of one element
compar = Pointer to comparison function
qsort will sort an array of elements
with using a comparison function.
memchr finds the firs occurrence of a character and return a pointer to it.
memcmp
check the size of a string and string2 and return a value
less 0 string1 lesser than string2
equal 0 string1 equal string2
greater 0 string1 greater than string2
memcpy
Copy a string into another variable important here is to give the size of the string
memmove
str1: target memory block (at least size bytes in size)
str2: source memory block (at least size bytes in size)
n: number of bytes to be copied (The type size_t corresponds usually int))
memset
memset Fill / overwrite memory region with certain characters
str = Target memory block /c string
c = value byte that is used to overwrite
n = number of chars to be copied
strcat
The strcat function concatenates two strings.
str1 = target string to be added to source
str2 = source string to copied, including '\ 0' at the end of destination.
null byte of destination will be overwritten.
strchr
strchr finds the first occurrence of a character and return a pointer to it.
strcmp
strcmp Compares 2 C strings.
If both strings are identical, the return value of strcmp is 0.
If the string s1 less than s2, the return value is less than 0,
and s1 is greater than s2, then the return value greater than 0
strcoll
strcoll compares 2 strings
strcpy
strcpy copy a c string pointed by str2 into the array pointed by str1 including the terminating null character.
strcspn
strcspn find the first occurrence of any character in str2
strerror
returns a pointer to a string that describes the error code passed in the argument errnum
strlen
calculates the size of a char array
strncat
appends the src string to the dest string, overwriting the null byte ('\0') at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the dest string must have enough space for the result.
strncmp
The strcmp() function compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. The strncmp() function is similar, except it only compares the first (at most) n characters of s1 and s2.
strncpy
Copy a given Number of Chars into another string
strpbrk
finds the first occurrence of a character.
strrchr
strrchr () is a string function that finds the last occurrence of a character in a string. As a result, the pointer comes to this character or the null pointer if this character is not found.
In the following example, a string is read by fgets. fgets hangs at the end of a New-line character (\ n). We are looking for a pointer to this character and replace it with a '\ 0' characters.
strspn
check different char by position
strstr
change a word by another word in string.
strxfrm
The function strxfrm () transforms a null-terminated C string according to local settings. Thus the string can be safely compared using strcmp () with another. The transformed string is stored in a new string.
The function asctime() converts the time in the struct ptr to a character string of the format: Day Month Date Hour:Minute:Second Year\n\0
clock
The clock() function returns the processor time since the program started, or -1 if that information is unavailable.
To convert the return value to seconds, divide it by CLOCKS_PER_SEC. (Note: if your compiler is POSIX compliant, then CLOCKS_PER_SEC is always defined as 1000000.)
clock_t
The type is the arithmetic type a-type of an object that you declare to hold the value returned by clock, representing elapsed processor time.
c/time.h/clock_t.txt · Last modified: 2013/01/22 22:02 (external edit)
Page Tools
Edit this page
Old revisions
Backlinks
Back to top
CLOCKS_PER_SEC
The macro yields the number of clock ticks, returned by clock, in one second.
The ctime() function shall convert the time pointed to by clock, representing time in seconds since the Epoch, to local time in the form of a string. It shall be equivalent to
asctime(localtime(clock))
1970-01-01 00:00:00 +0000 (UTC).
return value
The ctime() function shall return the pointer returned by asctime() with that broken-down time as an argument.
Upon successful completion, ctime_r() shall return a pointer to the string pointed to by buf. When an error is encountered, a null pointer shall be returned.
difftime
gmtime
localtime
mktime
strftime
strptime
time
time_t
tm
Under tm_ all are same. but define something other as like tm_sec for second. so this description is fot all tm_
struct tm contains members that describe various properties of the calendar time. The members shown above can occur in any order,
interspersed with additional members. The comment following each member briefly describes its meaning.
The member tm_isdst contains:
a positive value if Daylight Saving Time is in effect
zero if Daylight Saving Time is not in effect
a negative value if the status of Daylight Saving Time is not known (so the target environment should attempt to determine its status)
convert a byte to wide character btowc returns the wide two byte character “wchar_t” converted from the single byte “string” character (char).
return value
If the argument is not a valid multibyte sequence of length 1 btowc returns WEOF.
output is affected by the current LC_TYPE locale.
fgetwc
fgetwc reads in a single character from Stream and returns its value as a wide character.
fgetws
fgetws reads wide characters into “*restrict” from “stream”
fgetws will also stop reading if it encounters a newline character. In which case,
the newline character will put into the string as long as the number of characters
does not exceed “length - 1”.
The function will also stop reading if it reaches the end of the stream.
If an error or EOF occurs, the function returns NULL instead of a widechar string Depending
on whether the mode is binary or text, the function will read “*stream” as a wide-character or multibyte-character string, respectively.
fputwc
fputwc writes a single wide-character to the stream at the position of the file pointer and advances the pointer.
If the write was successful, the character that was written is returned. Otherwise, the function returns WEOF.
fputws
fputws writes the wide-character string to the stream, at the position of the file pointer and advances the pointer.
If the write was successful, a nonnegative integer value is returned. Otherwise, the function returns WEOF.
fwide
fwide shall determine the orientation of the stream pointed to by stream.
return value
greater than 0 if, after the call, the stream has wide-orientation
less than 0 if the stream has byte-orientation
0 if the stream has no orientation.