Standard library functions in C

These are the inbuilt functions whose function declaration and definition are written in their respective header file.If you want to use these functions you have to include respective header file in your program.

Following is the list of headers with some of their functions :

<stdio.h>

Includes file I/O functions.


fflush(...)

Flushes a stream

eg. fflush(stdin);



scanf(...)


Reads formatted input from stdin.
int a;
float b;     
scanf("%d %f",&a,&b);
The value entered is stored at the specified address.
            a      b
         _____________
Value   |  10  | 20.2 |
        |______|______|
        | FFF4 | FFF0 |
Address |______|______|

printf(...)

Writes formatted output to stdout.

%d ---> int

%c ---> char

%f ---> float,double.

%s --> string
printf("%d %f",a,b);
We write %d for a (an int) and %f for b (a float).

O/P 10 20.200001

If we want 20.2 we can use precision i.e %.1f . This would print 1 digit after decimal point. 

getchar()

Gets a character from stdin.
getchar()=='y'
Will compare the entered character with y.


<conio.h>

Includes console I/O functions.

clrscr()

Clears the current text window and places the cursor in the upper left hand corner.

getch()

Gets a character from console but does not echo it on the screen.It holds the screen until a character is entered.


<math.h>

Includes common mathematical functions.

sqrt(...)

Finds +ve square root of input value.

eg. sqrt(9)

pow(...)

pow(base,exponent) gives value base raised to exponent.

pow(2,5) gives 2 raise to 5 =32


floor(...)

Rounds down the value.

floor(12.99) would return 12. (largest integer < 12.99)


ceil(...)

Rounds up the value.

ceil(12.01) would return 13.  (smallest integer not < 12.01)


<string.h>

Includes the string functions.These functions are covered here.


<stdlib.h>

Includes memory allocation functions(malloc,calloc,...),numeric conversion functions ,etc.

atoi(...)

Converts a string to integer.

atoi("12.55") would give 12.


<ctype.h>

Includes character checking and mapping functions.

isalpha(...)

Checks whether character passed is alphabet.

isalpha('c') would return a non zero value as 'c' is an alphabet.


tolower(...)

Converts a given letter to lower case.

tolower('C') would give c.

2 comments:

  1. Wow, it is so interesting bog my dear friend ! it is helpful for beginner

    ReplyDelete
  2. Very helpful to all. Thank you for contributing to simplifying c

    ReplyDelete