0% found this document useful (0 votes)
36 views

C Unit-4 PPT

bj

Uploaded by

24f3000279
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

C Unit-4 PPT

bj

Uploaded by

24f3000279
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Programming Using ‘C’

Language

Unit -4
Standard Library Functions

• Library functions are the inbuilt function in C that are grouped and placed at
a common place called the library.
• The library functions are created by the designers of compilers.
• All C standard library functions are defined inside the different header files
saved with the extension .h.
• We need to include these header files in our program to make use of the
library functions defined in such header files.
SN Header Description
file
1 stdio.h This is a standard input/output header file. It contains all the
library functions regarding standard input/output like printf(),
scanf(), gets(), puts(), getc(), putc(), fopen(), fclose(), fprintf(),
fscanf(), fgets(), fputs(), fgetc(), fputc(), fseek(), ftell(), rewind()
etc
2 conio.h This is a console input/output header file like clrscr(), getch()
etc
3 string.h It contains all string related library functions like gets(), puts(),
strlen(), strcpy(),strcat(), strcmp(), strrev(), strlwr(), strupr() etc.
4 stdlib.h This header file contains all the general library functions like
malloc(), calloc(), realloc(), free(), exit() etc.
5 math.h This header file contains all the math operations related
functions like sqrt(), pow() etc.
6 ctype.h This header file contains all character handling functions like
isalnum(), isalpha etc
7 process.h This header file contains function declarations and macros used
conio.h header file functions

Sr.No. Functions
Description

1 clrscr() This function is used to clear the output screen.


2 getch() It reads character from keyboard
3 It reads character from keyboard and echoes to
getche()
o/p screen
4 textcolor() This function is used to change the text color
5 textbackground() This function is used to change text background
math.h header file functions
There are various methods in math.h header file. The commonly used
functions of math.h header file are given below.

SN Function Description
1) ceil(number) rounds up the given number. It returns the integer
value which is greater than or equal to given
number.
2) floor(number) rounds down the given number. It returns the
integer value which is less than or equal to given
number.
3) sqrt(number) returns the square root of given number.
4) pow(base, exponent) returns the power of given number.
5) abs(number) returns the absolute value of given number.
6) sin(number)/ returns the sin/cos/tan value of given number in
cos(number)/ radian .
tan(number)
Example:

#include<stdio.h>
#include <math.h>
void main()
{
printf("\n%f",ceil(3.6));
printf("\n%f",ceil(3.3));
printf("\n%f",floor(3.6)); Output:
printf("\n%f",floor(3.2)); 4.000000
printf("\n%f",sqrt(16)); 4.000000
printf("\n%f",sqrt(7)); 3.000000
printf("\n%f",pow(2,4)); 3.000000
printf("\n%f",pow(3,3)); 4.000000
printf("\n%d",abs(-12)); 2.645751
16.000000
} 27.000000
12
ctype.h header file functions

Sr.No. Function Description


1 int isalnum(int c) This function checks whether the passed character is
alphanumeric.
2 int isalpha(int c) This function checks whether the passed character is
alphabetic.
3 int isdigit(int c) This function checks whether the passed character is
decimal digit.
4 int islower(int c) This function checks whether the passed character is
lowercase letter.
5 int ispunct(int c) This function checks whether the passed character is a
punctuation character.
6 int isspace(int c) This function checks whether the passed character is
white-space.
7 int isupper(int c) This function checks whether the passed character is an
uppercase letter.
This library also contains two conversion functions that accepts and
returns an "int".

Sr.No Function Description


.
1 int tolower(int c) This function converts uppercase letters to
lowercase.
2 int toupper(int c) This function converts lowercase letters to
uppercase.
Example:
#include <stdio.h>
#include <ctype.h>
void main()
{
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (isalnum(ch))
printf("%c is an alphanumeric character.\n", ch);
else
printf("%c is not an alphanumeric character.\n", ch);
}

Output:
Enter a character: H
H is an alphanumeric character.

Enter a character: %
% is not an alphanumeric character.
process.h header file functions
S.No. Function Description
creates a new thread of execution within the current
1 _beginthread
process.

2 _endthread terminates a thread created by _beginthread.

returns the process identification number for the calling


3 _getpid
process.
perform cleanup operations and return without
4 _cexit
terminating the calling process.
load and execute a new child process by placing it in
5 _exec memory previously occupied by the parent process.
Sufficient memory must be available.
load and execute a new child process. The current
process may or may not continue to execute
6 _spawn asynchronously. Creating a new subprocess requires
enough memory in which both the child process and the
current program can execute.
Command Line Arguments
• The arguments passed from command line are called command line
arguments.
• They are used when we need to control our program from outside instead
of hard-coding it.
• They make installation of programs easier.
• They are handled by the main() function.
• If you want to pass command line arguments then you will have to define
the main() function with two arguments. The first argument defines the
number of command line arguments and the second argument is the list of
command line arguments.
Syntax:
int main(int argc, char *argv[] )
• argc counts the number of arguments to be passed.
• The argv[] denotes a pointer array pointing to every argument that has
been passed to your program.
• argv[argc] is a NULL pointer.
• The name of the program is stored in argv[0], the first command-line
parameter in argv[1], and the last argument in argv[n].
Example: Let's see the example of command line arguments where we are
passing one argument with file name.

#include <stdio.h>
void main(int argc, char *argv[] )
{
printf("Program name is: %s\n", argv[0]);
if(argc < 2)
{
printf("No argument passed through command line.\n");
}
else
{
printf("First argument is: %s\n", argv[1]);
}
}
Output:.When we write in command line like ./program hello then
output is
Program name is: program
First argument is: hello

You might also like