Page Nav

HIDE

Grid

GRID_STYLE

Classic Header

{fbt_classic_header}

Search This Blog

Notes:

latest

07_Library Functions_C programming



Typecasting


Typescasting is nothing but it is a process of converting one data type into another data type by using casting operator.

Typecasting is of two types i.e. Implicit typecasting and Explicit typecasting.

For e.g.



Implicit typecasting


#include<stdio.h>

int main()

{
int a;

char c = "g";

a=c;

printf("The value of "g" in integer is : %d",a);

return 0;

}


Explicit typecasting

#include<stdio.h>

int main()

{
int a=4, b=7;

float c;

c=int(a/b);

printf("The value of "g" in integer is : %d",c);

return 0;

}


Library Functions



stdio.h

 

printf()

This function is used to print the character, string, float, integer, octal and hexadecimal values onto the output screen

scanf()

This function is used to read a character, string, numeric data from keyboard.

getc()

It reads character from file

gets()

It reads line from keyboard

getchar()

It reads character from keyboard

puts()

It writes line to o/p screen

putchar()

It writes a character to screen

clearerr()

This function clears the error indicators

f open()

All file handling functions are defined in stdio.h header file

f close()

closes an opened file

getw()

reads an integer from file

putw()​

writes an integer to file​

f getc()​

reads a character from file​

putc()​

writes a character to file​

f putc()​

writes a character to file​

f gets()​

reads string from a file, one line at a time​

f puts()​

writes string to a file​

f eof()​

finds end of file​

f getchar​

reads a character from keyboard​

f getc()​

reads a character from file​

f printf()​

writes formatted data to a file​

f scanf()​

reads formatted data from a file​

f getchar​

reads a character from keyboard​

f putchar​

writes a character from keyboard​

f seek()​

moves file pointer position to given location​

SEEK_SET​

moves file pointer position to the beginning of the file​

SEEK_CUR​

moves file pointer position to given location​

SEEK_END​

moves file pointer position to the end of file.​

f tell()​

gives current position of file pointer​

rewind()​

moves file pointer position to the beginning of the file​

putc()​

writes a character to file​

sprint()​

writes formatted output to string​

sscanf()​

Reads formatted input from a string​

remove()​

deletes a file​

fflush()​

flushes a file​


conio.h

 

clrscr()

This function is used to clear the output screen.

getch()

It reads character from keyboard

getche()

It reads character from keyboard and echoes to o/p screen

textcolor()

This function is used to change the text color

textbackground()

This function is used to change text background


string.h

 

String Function

Description

strcat ( )

Concatenates str2 at the end of str1

strncat ( )

Appends a portion of string to another

strcpy ( )

Copies str2 into str1

strncpy ( )

Copies given number of characters of one string to another

strlen ( )

Gives the length of string

strcmp ( )

Returns 0 if str1 is same as str2, Retyrns <0 if str1<str2. Returns >0 if str1>str2

strcmpi ( )

Same as strcmp( ) function but this function negotiates case "A" and "a"are treated as same.

strchr ( )

Returns pointer to first occurrence of char in str1

strrchr ( )

Last occurrrence of given character in a string is found

strstr ( ) 

Returns pointer to first occurrence of str2 in str1

strrstr ( )

Returns pointer to last occurrence of str2 in str1

String Function

Description

strdup ( )

Duplicater th string

strlwr ( )

Converts string to lowercase

strupr ( )

Converts the string to uppercase

strrev ( )

Reverses the string

strset ( ) 

Sets all character in a string to given character

strnset ( )

Sets the portion of characters in a string to given character

strtok ( ) 

Tokenizing given string using delimiter

memset ( )​

Used to initilize a specified number of bytes to null or any other value in the buffer​

memicmp ( )​

Used to compare specified number of characters from two buffers regardless of the case of the character.​

memchr ( ) ​

Used to locate the first occurrence of the character in the specified string.​

memcpy ( )​

Used to copy a specified number of bytes from one memory to another​

memmove ( )​

Used to copy a specified number of bytes from one memory to another or to overlap on same memeory​

memcmp ( )​

Used to compare specified  number of characters from two buffers​


stdlib.h

Function

Description

malloc()

This function is used to allocate space in memory during the execution of the
program.

calloc()

This function is also like malloc () function. But calloc () initializes the allocated
memory to zero. But, malloc() doesn’t

realloc()

This function modifies the allocated memory size by malloc () and calloc ()
functions to new size

free()

This function frees the allocated memory by malloc (), calloc (), realloc () functions
and returns the memory to the system.

abs()

This function returns the absolute value of an integer . The absolute value of a
number is always positive. Only integer values are supported in C.

div()

This function performs division operation

abort()

It terminates the C program

exit()

This function terminates the program and does not return any value

system()

This function is used to execute commands outside the C program.

atoi()

Converts string to int

atol()

Converts string to long

atof()

Converts string to float

strtod()

Converts string to double

strtol()

Converts string to long

getenv()

This function gets the current value of the environment variable

setenv()

This function sets the value for environment variable

putenv()

This function modifies the value for environment variable

perror()

This function displays most recent error that happened during library function call.

rand()

This function returns the random integer numbers

delay()

This function Suspends the execution of the program for particular time


math.h

 

floor ( )

This function returns the nearest integer which is less than or equal to the argument passed to this function.

round ( )

This function returns the nearest integer value of the float/double/long double argument passed to this function. If decimal value is from “.1 to .5”, it returns integer value less than the argument. If decimal value is from “.6 to .9”, it returns the integer value greater than the argument.

ceil ( )

This function returns nearest integer value which is greater than or equal to the argument passed to this function.

sin ( )

This function is used to calculate sine value.

cos ( )

This function is used to calculate cosine.

cosh ( )

This function is used to calculate hyperbolic cosine.

exp ( )

This function is used to calculate the exponential “e” to the xth power.

tan ( )​

This function is used to calculate tangent.​

tanh ( )​

This function is used to calculate hyperbolic tangent.​

sinh ( )​

This function is used to calculate hyperbolic sine.​

log ( )​

This function is used to calculates natural logarithm.​

log10 ( )​

This function is used to calculates base 10 logarithm.​

sqrt ( )​

This function is used to find square root of the argument passed to this function.​

pow ( )​

This is used to find the power of the given number.​

trunc.(.)​

This function truncates the decimal value from floating point value and returns integer value.​


time.h

 

Functions

Description

setdate()

This function used to modify the system date

getdate()

This function is used to get the CPU time

clock()

This function is used to get current system time

time()

This function is used to get current system time as structure

difftime()

This function is used to get the difference between two given times

strftime()

This function is used to modify the actual time format

mktime()

This function interprets tm structure as calendar time

localtime()​

This function shares the tm structure that contains date and time informations​

gmtime()​

This function shares the tm structure that contains date and time informations​

ctime()​

This function is used to return string that contains date and time informations​

asctime()​

Tm structure contents are interpreted by this function as calendar time. This time is converted into string.​


ctype.h

Functions

Description

isalpha()

checks whether character is alphabetic

isdigit()

checks whether character is digit

isalnum()

Checks whether character is alphanumeric

isspace()

Checks whether character is space

islower()

Checks whether character is lower case

isupper()

Checks whether character is upper case

isxdigit()

Checks whether character is hexadecimal

iscntrl()

Checks whether character is a control character

isprint()

Checks whether character is a printable character​

ispunct()​

Checks whether character is a punctuation​

isgraph()

Checks whether character is a graphical character​

tolower()​

Checks whether character is alphabetic & converts to lower case​

toupper()

Checks whether character is alphabetic & converts to upper case​

Download the PDF file


-----------------------------------------------------------------------------------------------------------------------------
The End
-----------------------------------------------------------------------------------------------------------------------------

No comments

If you have any doubts, Please let me know,

Click here to show more posts