You are on page 1of 20

Welcome To Seminar On Standard library in c

contents
1. Introduction 2. C programming library functions 2.1 <stdio.h> 2.2<String.h> 2.3<math.h> 2.4<ctype.h> 2.5<stdlib.h 2.6<time.h> 3 Conclusion 4 References

Introduction

Libraries for use by C programs really consist of two parts: header files that define types and macros and declare variables and functions; and the actual library that contains the definitions of the variables and functions.

Every implementation of C comes with a standard library of predefined functions. Note that, in programming, a library is a collection of functions. The functions that are common to all versions of C are known as the C Standard Library.

C programming library functions

<stdio.h>-standard input and output getc() getchar() gets() printf() fflush()

gets()
Description:
This function accepts a string from the standard input device. The input string may consist of multiple word. Typing enter key completes the Input.

Example:
#include <stdio.h> Void main(void) { char string[50]; printf("Input a string:"); gets(string); printf("The string you typed is); puts (string); } Output is: Input a string: string input The string you typed is string input

<String.h>- string functions

memchr(); memcmp(); strlen(); strcat(); strncat();

strlen()
The strlen() function takes one arguement that can be a string constant or a variable. It counts number of characters present in the string. Null character is used to mark the end of the string, so it is not counted. #include<stdio.h> #include<string.h> Void main(void { Char str [31]; int len; Printf(\nenter string:); gets(str); len=strlen(str); Printf(no. of characters in %s=%d\n,str,len); } output-enter string: turbo No. of characters in turbo =5

<math.h>-Mathematical function
abs() acos() asin() Sqrt() ceil()

Example:ceil()
Description: The ceil() function returns the smallest integer no less than num. Example: y = 6.04; x = ceil( y ); RESULT: Sets x to 7.0

<ctype.h>-Character class test

isalnum(); isalpha(); iscntrl(); isdigit(); islower();

isalpha() Description: The function isalpha() returns non-zero if its argument is a letter of the alphabet. Otherwise, zero is returned. Example: char c; scanf( "%c", &c ); if(( isalpha(c) ) printf( "You entered a letter of the alphabet\n" );

<Stdlib.h>- Utility functions

abort(); atoi(); atexit(); atof(); bsearch();

example
atoi()
Description: The atoi() function converts str into an integer, and returns that integer. str should start with some sort of number, and atoi() will stop reading from str as soon as a nonnumerical character has been read. Example: i = atoi( "512.035" ); RESULT: i set to 512.

<time.h>- Time and date functions


asctime(); clock(); difftime(); gmtime();

clock()

Syntax: #include <time.h>


Description: 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.)

conclusion

References
http://www.elook.org/programming/c/stddate.html http://www.elook.org/programming/c/ http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

You might also like