Showing posts with label The C Standard Library Reference. Show all posts
Showing posts with label The C Standard Library Reference. Show all posts

Monday, 19 May 2014

C Library -

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

C Library - <time.h>

Introduction

The time.h header defines four variable types, two macro and various functions for manipulating date and time.

Library Variables

Following are the variable types defined in the header time.h:
S.N.Variable & Description
1size_t 
This is the unsigned integral type and is the result of the sizeof keyword.
2clock_t 
This is a type suitable for storing the processor time.
3time_t is 
This is a type suitable for storing the calendar time.
4struct tm 
This is a structure used to hold the time and date.
The tm structure has the following definition:
struct tm {
   int tm_sec;         /* seconds,  range 0 to 59          */
   int tm_min;         /* minutes, range 0 to 59           */
   int tm_hour;        /* hours, range 0 to 23             */
   int tm_mday;        /* day of the month, range 1 to 31  */
   int tm_mon;         /* month, range 0 to 11             */
   int tm_year;        /* The number of years since 1900   */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365  */
   int tm_isdst;       /* daylight saving time             */
};

Library Macros

Following are the macros defined in the header time.h:
S.N.Macro & Description
1NULL
This macro is the value of a null pointer constant.
2CLOCKS_PER_SEC 
This macro represents the number of processor clocks per second.

Library Functions

Following are the functions defined in the header time.h:
S.N.Function & Description
1char *asctime(const struct tm *timeptr)
Returns a pointer to a string which represents the day and time of the structure timeptr.
2clock_t clock(void)
Returns the processor clock time used since the beginning of an implementation-defined era (normally the beginning of the program).
3char *ctime(const time_t *timer)
Returns a string representing the localtime based on the argument timer.
4double difftime(time_t time1, time_t time2)
Returns the difference of seconds between time1 and time2 (time1-time2).
5struct tm *gmtime(const time_t *timer)
The value of timer is broken up into the structure tm and expressed in Coordinated Universal Time (UTC) also known as Greenwich Mean Time (GMT).
6struct tm *localtime(const time_t *timer)
The value of timer is broken up into the structure tm and expressed in the local time zone.
7time_t mktime(struct tm *timeptr)
Converts the structure pointed to by timeptr into a time_t value according to the local time zone.
8size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)
Formats the time represented in the structure timeptr according to the formatting rules defined in format and stored into str.
9time_t time(time_t *timer)
Calculates the current calender time and encodes it into time_t format.

Posted By MIrza Abdul Hannan3:26:00 pm

C Library -

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

C Library - <string.h>

Introduction

The string .h header defines one variable type, one macro and various functions for manipulating arrays of characters.

Library Variables

Following is the variable type defined in the header string.h:
S.N.Variable & Description
1size_t 
This is the unsigned integral type and is the result of the sizeof keyword.

Library Macros

Following is the macro defined in the header string.h:
S.N.Macro & Description
1NULL
This macro is the value of a null pointer constant.

Library Functions

Following are the functions defined in the header string.h:
S.N.Function & Description
1void *memchr(const void *str, int c, size_t n)
Searches for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to by the argument str.
2int memcmp(const void *str1, const void *str2, size_t n)
Compares the first n bytes of str1 and str2.
3void *memcpy(void *dest, const void *src, size_t n)
Copies n characters from src to dest.
4void *memmove(void *dest, const void *src, size_t n)
Another function to copy n characters from str2 to str1.
5void *memset(void *str, int c, size_t n)
Copies the character c (an unsigned char) to the first n characters of the string pointed to by the argument str.
6char *strcat(char *dest, const char *src)
Appends the string pointed to by src to the end of the string pointed to by dest.
7char *strncat(char *dest, const char *src, size_t n)
Appends the string pointed to by src to the end of the string pointed to by dest up to n characters long.
8char *strchr(const char *str, int c)
Searches for the first occurrence of the character c (an unsigned char) in the string pointed to by the argument str.
9int strcmp(const char *str1, const char *str2)
Compares the string pointed to by str1 to the string pointed to by str2.
10int strncmp(const char *str1, const char *str2, size_t n)
Compares at most the first n bytes of str1 and str2.
11int strcoll(const char *str1, const char *str2)
Compares string str1 to str2. The result is dependent on the LC_COLLATE setting of the location.
12char *strcpy(char *dest, const char *src)
Copies the string pointed to by src to dest.
13char *strncpy(char *dest, const char *src, size_t n)
Copies up to n characters from the string pointed to by src to dest.
14size_t strcspn(const char *str1, const char *str2)
Calculates the length of the initial segment of str1 which consists entirely of characters not in str2.
15char *strerror(int errnum)
Searches an internal array for the error number errnum and returns a pointer to an error message string.
16size_t strlen(const char *str)
Computes the length of the string str up to but not including the terminating null character.
17char *strpbrk(const char *str1, const char *str2)
Finds the first character in the string str1 that matches any character specified in str2.
18char *strrchr(const char *str, int c)
Searches for the last occurrence of the character c (an unsigned char) in the string pointed to by the argument str.
19size_t strspn(const char *str1, const char *str2)
calculates the length of the initial segment of str1 which consists entirely of characters instr2.
20char *strstr(const char *haystack, const char *needle)
Finds the first occurrence of the entire string needle (not including the terminating null character) which appears in the string haystack.
21char *strtok(char *str, const char *delim)
Breaks string str into a series of tokens separated by delim.
22size_t strxfrm(char *dest, const char *src, size_t n)
Transforms the first n characters of the string src into corrent locale and place them in the string dest.

Posted By MIrza Abdul Hannan3:25:00 pm

C Library -

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------
C Library - <stdlib.h>

Introduction

The stdlib .h header defines four variable types, several macros and various functions for performing general functions.

Library Variables

Following are the variable types defined in the header stdlib.h:
S.N.Variable & Description
1size_t 
This is the unsigned integral type and is the result of the sizeof keyword.
2wchar_t 
This is an integer type of the size of a wide character constant.
3div_t 
This is the structure returned by the div function.
4ldiv_t 
This is the structure returned by the ldiv function.

Library Macros

Following are the macros defined in the header stdlib.h:
S.N.Macro & Description
1NULL
This macro is the value of a null pointer constant.
2EXIT_FAILURE
This is the value for the exit function to return in case of failure.
3EXIT_SUCCESS
This is the value for the exit function to return in case of success.
4RAND_MAX 
This macro is the maximum value returned by the rand function.
5MB_CUR_MAX 
This macro is the maximum number of bytes in a multibyte character set which cannot be larger than MB_LEN_MAX.

Library Functions

Following are the functions defined in the header stdio.h:
S.N.Function & Description
1double atof(const char *str)
Converts the string pointed to by the argument str to a floating-point number (type double).
2int atoi(const char *str)
Converts the string pointed to by the argument str to an integer (type int).
3long int atol(const char *str)
Converts the string pointed to by the argument str to a long integer (type long int)
4double strtod(const char *str, char **endptr)
Converts the string pointed to by the argument str to a floating-point number (type double).
5long int strtol(const char *str, char **endptr, int base)
Converts the string pointed to by the argument str to a long integer (type long int).
6unsigned long int strtoul(const char *str, char **endptr, int base)
Converts the string pointed to by the argument str to an unsigned long integer (type unsigned long int).
7void *calloc(size_t nitems, size_t size)
Allocates the requested memory and returns a pointer to it.
8void free(void *ptr
Deallocates the memory previously allocated by a call to calloc, malloc, or realloc.
9void *malloc(size_t size)
Allocates the requested memory and returns a pointer to it.
10void *realloc(void *ptr, size_t size)
Attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc.
11void abort(void)
Causes an abnormal program termination.
12int atexit(void (*func)(void))
Causes the specified function func to be called when the program terminates normally.
13void exit(int status)
Causes the program to terminate normally.
14char *getenv(const char *name)
Searches for the environment string pointed to by name and returns the associated value to the string.
15int system(const char *string)
The command specified by string is passed to the host environment to be executed by the command processor.
16void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))
Performs a binary search.
17void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))
Sorts an array
18int abs(int x)
Returns the absolute value of x.
19div_t div(int numer, int denom)
Divides numer (numerator) by denom (denominator).
20long int labs(long int x)
Returns the absolute value of x.
21ldiv_t ldiv(long int numer, long int denom)
Divides numer (numerator) by denom (denominator).
22int rand(void)
Returns a pseudo-random number in the range of 0 to RAND_MAX.
23void srand(unsigned int seed)
This function seeds the random number generator used by the function rand.
24int mblen(const char *str, size_t n)
Returns the length of a multibyte character pointed to by the argument str.
25size_t mbstowcs(schar_t *pwcs, const char *str, size_t n)
Converts the string of multibyte characters pointed to by the argument str to the array pointed to by pwcs.
26int mbtowc(whcar_t *pwc, const char *str, size_t n)
Examines the multibyte character pointed to by the argument str.
27size_t wcstombs(char *str, const wchar_t *pwcs, size_t n)
Converts the codes stored in the array pwcs to multibyte characters and stores them in the string str.
28int wctomb(char *str, wchar_t wchar)
Examines the code which corresponds to a multibyte character given by the argumentwchar.

Posted By MIrza Abdul Hannan3:23:00 pm

C Library -

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

C Library - <stdio.h>

Introduction

The stdio .h header defines three variable types, several macros and various functions for performing input and output.

Library Variables

Following are the variable types defined in the header stdio.h:
S.N.Variable & Description
1size_t 
This is the unsigned integral type and is the result of the sizeof keyword.
2FILE 
This is an object type suitable for storing information for a file stream.
3fpos_t 
This is an object type suitable for storing any position in a file.

Library Macros

Following are the macros defined in the header stdio.h:
S.N.Macro & Description
1NULL
This macro is the value of a null pointer constant.
2_IOFBF, _IOLBF and _IONBF 
These are the macros which expand to integral constant expressions with distinct values and suitable for the use as third argument to the setvbuf function.
3BUFSIZ
This macro is an integer which represents the size of the buffer used by the setbuffunction.
4EOFM 
This macro is a negative integer which indicates an end-of-file has been reached.
5FOPEN_MAX 
This macro is an integer which represents the maximum number of files that the system can guarantee that can be opened simultaneously.
6FILENAME_MAX 
This macro is an integer which represents the longest length of a char array suitable for holding the longest possible filename. If the implementation imposes no limit, then this value should be the recommended maximum value.
7L_tmpnam 
This macro is an integer which represents the longest length of a char array suitable for holding the longest possible temporary filename created by the tmpnam function.
8SEEK_CUR, SEEK_END, and SEEK_SET 
These macros are used in the fseek function to locate different positions in a file.
9TMP_MAX 
This macro is the maximum number of unique filenames that the function tmpnam can generate.
10stderr, stdin, and stdout 
These macros are pointers to FILE types which correspond to the standard error, standard input, and standard output streams.

Library Functions

Following are the functions defined in the header stdio.h:
Follow the same sequence of functions for better understanding and to make use of Try itoption because file created in the first function will be used in subsequent functions.
S.N.Function & Description
1int fclose(FILE *stream)
Closes the stream. All buffers are flushed.
2void clearerr(FILE *stream)
Clears the end-of-file and error indicators for the given stream.
3int feof(FILE *stream)
Tests the end-of-file indicator for the given stream.
4int ferror(FILE *stream)
Tests the error indicator for the given stream.
5int fflush(FILE *stream)
Flushes the output buffer of a stream.
6int fgetpos(FILE *stream, fpos_t *pos)
Gets the current file position of the stream and writes it to pos.
7FILE *fopen(const char *filename, const char *mode)
Opens the filename pointed to by filename using the given mode.
8size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Reads data from the given stream into the array pointed to by ptr.
9FILE *freopen(const char *filename, const char *mode, FILE *stream)
Associates a new filename with the given open stream and same time closing the old file in stream.
10int fseek(FILE *stream, long int offset, int whence)
Sets the file position of the stream to the given offset. The argument offset signifies the number of bytes to seek from the given whence position.
11int fsetpos(FILE *stream, const fpos_t *pos)
Sets the file position of the given stream to the given position. The argument pos is a position given by the function fgetpos.
12long int ftell(FILE *stream)
Returns the current file position of the given stream.
13size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
Writes data from the array pointed to by ptr to the given stream.
14int remove(const char *filename)
Deletes the given filename so that it is no longer accessible.
15int rename(const char *old_filename, const char *new_filename)
Causes the filename referred to by old_filename to be changed to new_filename.
16void rewind(FILE *stream)
Sets the file position to the beginning of the file of the given stream.
17void setbuf(FILE *stream, char *buffer)
Defines how a stream should be buffered.
18int setvbuf(FILE *stream, char *buffer, int mode, size_t size)
Another function to define how a stream should be buffered.
19FILE *tmpfile(void)
Creates a temporary file in binary update mode (wb+).
20char *tmpnam(char *str)
Generates and returns a valid temporary filename which does not exist.
21int fprintf(FILE *stream, const char *format, ...)
Sends formatted output to a stream.
22int printf(const char *format, ...)
Sends formatted output to stdout.
23int sprintf(char *str, const char *format, ...)
Sends formatted output to a string.
24int vfprintf(FILE *stream, const char *format, va_list arg)
Sends formatted output to a stream using an argument list.
25int vprintf(const char *format, va_list arg)
Sends formatted output to stdout using an argument list.
26int vsprintf(char *str, const char *format, va_list arg)
Sends formatted output to a string using an argument list.
27int fscanf(FILE *stream, const char *format, ...)
Reads formatted input from a stream.
28int scanf(const char *format, ...)
Reads formatted input from stdin.
29int sscanf(const char *str, const char *format, ...)
Reads formatted input from a string.
30int fgetc(FILE *stream)
Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream.
31char *fgets(char *str, int n, FILE *stream)
Reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first.
32int fputc(int char, FILE *stream)
Writes a character (an unsigned char) specified by the argument char to the specified stream and advances the position indicator for the stream.
33int fputs(const char *str, FILE *stream)
Writes a string to the specified stream up to but not including the null character.
34int getc(FILE *stream)
Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream.
35int getchar(void)
Gets a character (an unsigned char) from stdin.
36char *gets(char *str)
Reads a line from stdin and stores it into the string pointed to by str. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.
37int putc(int char, FILE *stream)
Writes a character (an unsigned char) specified by the argument char to the specified stream and advances the position indicator for the stream.
38int putchar(int char)
Writes a character (an unsigned char) specified by the argument char to stdout.
39int puts(const char *str)
Writes a string to stdout up to but not including the null character. A newline character is appended to the output.
40int ungetc(int char, FILE *stream)
Pushes the character char (an unsigned char) onto the specified stream so that the this is the next character read.
41void perror(const char *str)
Prints a descriptive error message to stderr. First the string str is printed followed by a colon then a space.

Posted By MIrza Abdul Hannan3:22:00 pm

C Library -

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

C Library - <stddef.h>

Introduction

The stddef .h header defines various variable types and macros. Many of these definitions also appear in other headers.

Library Variables

Following are the variable types defined in the header stddef.h:
S.N.Variable & Description
1ptrdiff_t
This is the signed integral type and is the result of subtracting two pointers.
2size_t 
This is the unsigned integral type and is the result of the sizeof keyword.
3wchar_t 
This is an integral type of the size of a wide character constant.

Library Macros

Following are the macros defined in the header stddef.h:
S.N.Macro & Description
1NULL
This macro is the value of a null pointer constant.
2offsetof(type, member-designator)
This results in a constant integer of type size_t which is the offset in bytes of a structure member from the beginning of the structure. The member is given by member-designator, and the name of the structure is given in type.

Posted By MIrza Abdul Hannan3:18:00 pm

C Library -

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

C Library - <stdarg.h>

Introduction

The stdarg.h header defines a variable type va_list and three macros which can be used to get the arguments in a function when the number of arguments is not known ie. variable number of arguments.
A function of variable arguments is defined with the ellipsis (,...) at the end of the parameter list.

Library Variables

Following is the variable type defined in the header stdarg.h:
S.N.Variable & Description
1va_list 
This is a type suitable for holding information needed by the three macros va_start(), va_arg() and va_end().

Library Macros

Following are the macros defined in the header stdarg.h:
S.N.Macro & Description
1void va_start(va_list ap, last_arg)
This macro initializes ap variable to be used with the va_arg and va_end macros. Thelast_arg is the last known fixed argument being passed to the function ie. the argument before the ellipsis.
2type va_arg(va_list ap, type)
This macro retrieves the next argument in the paramater list of the function with type type.
3void va_end(va_list ap)
This macro allows a function with variable arguments which used the va_start macro to return. If va_end is not called before returning from the function, the result is undefined.

Posted By MIrza Abdul Hannan3:17:00 pm