SlideShare uma empresa Scribd logo
1 de 20
UNIT 4-HEADER FILES IN C
A header file is a file with extension .h which contains C function
declarations and macro definitions to be shared between several source
files.
Typesof Header files
 Sy stem header files: It iscomes withcompiler.
 User headerfiles: It is written by programmer.
You request to use a header file in your program by including it with the
C preprocessing directive #include, like you have seen inclusion
of stdio.hheader file, which comes along with your compiler.
Including a header file is equal to copying the content of the header file
but we do not do it because it will be error-prone and it is not a good
idea to copy the content of a header file in the source files, especially if
we have multiple source files in a program.
A simple practice in C or C++ programs is that we keep all the constants,
macros, system wide global variables, and function prototypes in the
header files and include that header file wherever it is required.
1. math.h header file in C:-
Function De s cr iption Exam ple
sqrt(x) square root of x
sqrt(4.0) is 2.0
sqrt(10.0) is 3.162278
exp(x) exponential (ex
)
exp(1.0) is 2.718282
exp(4.0) is 54.598150
log(x) natural logarithm of x (base e)
log(2.0) is 0.693147
log(4.0) is 1.386294
log10(x) logarithm of x (base 10)
log10(10.0) is 1.0
log10(100.0) is 2.0
Function De s cr iption Exam ple
fabs(x) absolute value of x
fabs(2.0) is 2.0
fabs(-2.0) is 2.0
ceil(x) rounds x to smallest integer not less than x
ceil(9.2) is 10.0
ceil(-9.2) is -9.0
floor(x) rounds x to largest integer not greater than x
floor(9.2) is 9.0
floor(-9.2) is -10.0
pow (x,y) x raised to pow er y (xy
) pow (2,2) is 4.0
fmod(x) remainder of x/y as floating-point number fmod(13.657, 2.333) is 1.992
sin(x) sine of x (x in radian) sin(0.0) is 0.0
cos(x) cosine of x (x in radian) cos(0.0) is 1.0
tan(x) tangent of x (x in radian) tan(0.0) is 0.0
Examples:-
 SUBMIT
#include <stdio.h>
#include <math.h>
int main()
{
printf("%fn",sqrt(10.0));
printf("%fn",exp(4.0));
printf("%fn",log(4.0));
printf("%fn",log10(100.0));
printf("%fn",fabs(-5.2));
printf("%fn",ceil(4.5));
printf("%fn",floor(-4.5));
printf("%fn",pow(4.0,.5));
printf("%fn",fmod(4.5,2.0));
printf("%fn",sin(0.0));
printf("%fn",cos(0.0));
printf("%fn",tan(0.0));
return 0;
}
Output
3.162278
54.598150
1.386294
2.000000
5.200000
5.000000
-5.000000
2.000000
0.500000
0.000000
1.000000
0.000000
2. ctype.hheaderfile inC:-
ctype.h header file contains the functions related to characters. Some of the useful library functions are: isalnum(),
isalpha(), isdigit(), isspace(), ispunct(), toupper(), tolower().
List of ctype.h header file’s libraryfunctions with explanation and
example programs
1) isalnum()
This function checks whether character is alphanumeric or not.
1
2
3
4
5
6
7
8
9
/* C example program of isalnum().*/
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
10
11
12
13
14
15
16
17
18
if(isalnum(ch))
printf("%c is an alphanumeric character.n",ch);
else
printf("%c is not an alphanumeric character.n",ch);
return 0;
}
First run:
Enter a character: H
H is an alphanumeric character.
Second run:
Enter a character: %
% is not an alphanumeric character.
2) isalpha()
This function checks whether character is alphabet or not.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* C example program of isalpha().*/
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if(isalpha(ch))
printf("%c is an alphabet.n",ch);
else
printf("%c is not an alphabet.n",ch);
return 0;
}
First run:
Enter a character: Y
Y is an alphabet.
Second run:
Enter a character: 9
9 is not an alphabet.
3) isdigit()
This function checks whether character is digit or not.
1
2
/* C example program of isdigit().*/
#include<stdio.h>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if(isdigit(ch))
printf("%c is a digit.n",ch);
else
printf("%c is not a digit.n",ch);
return 0;
}
First run:
Enter a character: Y
Y is not a digit.
Second run:
Enter a character: 9
9 is a digit.
4) isspace()
This function checks whether character is space or not.
5) isupper()
This function checks whether character is an uppercase character or not.
6) islower()
This function checks whether character is a lowercase character or not.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* C example program of isspace(), isupper(), islower() .*/
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if(isupper(ch))
printf("%c is an uppercase character.n",ch);
else if(islower(ch))
printf("%c is an lowercase character.n",ch);
else if(isspace(ch))
printf("%c is space.n",ch);
else
17
18
19
20
21
22
printf("%c is none from uppercase, lowercase and
space.n",ch);
return 0;
}
First run:
Enter a character: T
T is an uppercase character.
Second run:
Enter a character: t
t is an lowercase character.
Third run:
Enter a character: main
m is an lowercase character.
Fourth run:
Enter a character:
is space.
Fifth run:
Enter a character: *
* is none from uppercase, lowercase and space.
7) ispunct()
This function checks whether character is a punctuation character or not.
Punctuation characters are , . : ; ` @ # $ % ^ & * ( ) < > [ ]  / { } ! | ~ - _ + ? = ' "
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* C example program of ispunct() .*/
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if(ispunct(ch))
printf("%c is a punctuation character.n",ch);
else
printf("%c is not a punctuation character.n",ch);
return 0;
}
First run:
Enter a character: !
! is a punctuation character.
Second run:
Enter a character: ,
, is a punctuation character.
Third run:
Enter a character: +
+ is a punctuation character.
8) isprint()
This function checks whether character is printable or not.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* C example program of ispunct() .*/
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if(isprint(ch))
printf("%c is a printable character.n",ch);
else
printf("%c is not a printable character.n",ch);
return 0;
}
Enter a character: x
x is a printable character.
9) toupper()
This function returns character in upper case.
10) tolower()
This function returns character in lower case.
1
2
3
4
5
6
7
8
9
10
11
/* C example program of toupper() and tolower() .*/
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
printf("Upper case: %c, Lower case:
%cn",toupper(ch),tolower(ch));
12
13
14
15
return 0;
}
First run:
Enter a character: w
Upper case: W, Lower case: w
Second run:
Enter a character: 9
Upper case: 9, Lower case: 9
3. stdio.hheaderfile libraryfunctionsinC:-
1. perror() function of stdio.h in C.
In this article, we are going to learn about the perror() function of stdio.h header file in C programming language,
and use it prints a descriptive error message to stderr.
2. puts() and putchar() functions of stdio.h in C.
In this article, we are going to learn about the putchar() and puts() function of stdio.h header file in C
programming language and use it put string and characters on console.
3. gets() function of stdio.h in C.
In this article, we are going to learn about the gets() function of stdio.h header file in C programming language,
and use it get string and then print it on console.
4. putc() function of stdio.h in C.
In this article, we are going to learn about the putc() function of stdio.h header file in C programming language,
and use it to put characters inside a file with the help of file pointer.
5. fgets() function of stdio.h in C.
In this article, we are going to learn about the fgets() function of stdio.h header file in C programming language
and use it while getting the characters from file pointer.
6. fscanf() function of stdio.h in C.
In this article, we are going to learn about the fscanf() function of stdio.h header file in C programming language
and use it to scan rewind variables.
Explainationswithexamples:-
1) perror() function in C:-
This function is very useful as it prints the error message on the screen. All we have to do is if you have a situation
where we caught an error; call this function with a parameter of string.
The String which will be printed first, a colon, a space then the error message.
Example:
perror("here is the error");
will print →
here is the error : ERROR MESSAGE.
stdio.h - perror() function Example in C
#include <stdio.h>
int main ()
{
// defining the file pointer
FILE *f;
// rename file name
rename("abc.txt", "abcd.txt");
// open file
f = fopen("file.txt", "r");
// condition if error then print error
if( f == NULL ) {
perror("Error in Code is: ");
return(-1);
}
// close the file
fclose(f);
return(0);
}
Output
2) puts( ) and putchar( ) functions:-
The function puts() is used to print strings while putchar() function is used to print character as their names
specifies.
These functions are from the stdio.h class doing the jobs related to strings.
Example:
puts("I AM A STRING");
Output:
I AM A STRING
putchar("a");
Output:
a
You can also use printf() which havemore options then these two functions.
#include <stdio.h>
#include <string.h>
int main ()
{
// initializing the variables
char a[15];
char b[15];
char c;
// coming string in a and b
strcpy(a, "includehelp");
strcpy(b, "ihelp");
// put a and b
puts(a);
puts(b);
// printing characters
for(c = 'Z' ; c >= 'A' ; c--)
{
putchar(c);
}
return(0);
}
Output
3) gets( ) in C:-
The function gets() is used to scan a string from the user without any n or till the n character. This function is
from the string.h class doing the jobs related to strings.
Example:
gets(str) ;
User input: "I AM A STRING"
Output:
I AM A STRING
You can also use scanf() which shavemore options then this function.
stdio.h - gets() function Example in C
#include <stdio.h>
int main ()
{
//initializing the type of variables
char str[50];
char c;
//message for user
printf("Please enter a string : ");
gets(str);
//printing the result
printf("Your String: %snn", str);
//message for user
printf("Please enter a character: ");
c = getchar();
//printing the result
printf("Your Character: ");
putchar(c);
return(0);
}
Output
4) putc( ) in C:-
If you are handling files in your application then coping one file into other or from the same file will something
you will encounter. Therefore, using the function putc() will help you doing this.
The Function is use to write a single character in file. TheFunction needs only two parameters first a character and
second is the file itself.
Example:
putc('a', FILE);
//Here, FILE is the file variable.
Output:
It will write 'a' on the file at the current
position of the cursor.
Examplesalreadydone inclass.
5) fgets( ) inC:-
If you are handling files in your application then reading from a file is something that you cannot ignore.
Therefore, the function fgets() will help you doing this.
The Function is use to read a string from a file. The Function needs only three parameters, first a character array,
second is the number of character you want to read and the third is the file itself.
Example:
fgets (str, 60, F);
//Here, str is a character array, F is the file variable.
It will read 60 characters from the file from the current position of the cursor.
stdio.h - fgets() function Example in C
#include <stdio.h>
int main ()
{
//initializing the file pointer
//and type of variables
FILE *F;
char str[60];
//open file abc in read mode
F = fopen("abc.txt" , "r");
if(F == NULL) {
perror("Error is:");
return(-1);
}
if( fgets (str, 60, F)!=NULL ) {
//printing the output on console
puts(str);
}
fclose(F);
return(0);
}
Output
6) fscanf( ) in C:-
This function is just like scanf() function, but instead of standard input, this read data from the file. Using this
function is simple if you already knew about the scanf() function.
This, fscanf() function requires one more parameter then the scanf() function and that parameter is the File
object. Rest of the argument are just as the scanf() function.
Syntax:
fscanf(F, "%s", a);
Here, F is the file object, a is the character array and "%s" string denoting the input value must be string.
This will read a string from the file from the current position of the cursor. You can do same with integers etc.
4. stdlib.h library functions in C:-
LIST OF INBUILT C FUNCTIONS IN STDLIB.H FILE:
Function Description
malloc()
This function is used to allocate space in memory during the execution ofthe
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 ofan integer . The absolute value ofa
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 programand 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 ofthe 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 randominteger numbers
delay() This function Suspends the execution ofthe programfor particular time
a) atof():-
Converts the string str to a decimal. If there are any white-space characters at the beginning of the string str then
they are skipped. For example, in the string " 123", white-space characters present at the beginning of the
string will be skipped and the conversion will start from the character '1'. The conversion stops if there is a
character which is not a number. For example, in the string "123a12", the conversion will stop after converting
"123" as soon as it encounters the non-numeric character 'a'.
If the string str doesn't form any valid floating-point number then 0.0 is returned.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char str[10] = "3.14";
printf("The value is %fn",atof(str));
return 0;
}
Output
The value is 3.140000
b) atoi( ) in C:-
Converts the string str to an integer. If there are any white-space characters at the beginning of the string str then
they are skipped. For example, in the string " 123", white-space characters present at the beginning of the string
will be skipped and the conversion will start from the character '1'. The conversion stops if there is a character
which is not a number. For example, int the string, "123a12" the conversion will stop after converting "123" as
soon as it encounters the non-numeric character 'a'.
If the string str doesn't form any valid integer number then 0 is returned.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char str[10] = "55";
printf("The value is %dn",atoi(str));
return 0;
}
Output
The value is 55
5. process.h library functions in C:-
process.h’ is a header file which includes macros and declarations. These are especially u sed during work with thread
and processes. There is no standard for process.h functions. They depend on compiler whichwe use.
1. Some of the standard member functions of process.h header files are,
2. __________________________________________________________
3. Function Name Description
4. execle - It loads & executes new child process by
5. placing it in memory previously occupied by
6. the parent process.
7. spawnv - Parameters are passed as an array of pointers.
8. It loads & executes new child process.
9. getpid - It returns the process identifier.
10. execlp - It loads & executes a new child process by
11. placing it in memory previously occupied by
12. the parent process.
EXAMPLE:-
1. /* Program to demonstrate process.h header file working.
2. Creation Date : 06 Nov 2010 07:43:10 PM
3. Author : www.technoexam.com [Technowell, Sangli] */
4.
5. #include <stdio.h>
6. #include <conio.h>
7. #include <process.h>
8.
9. int main(void)
10. {
11. clrscr();
12. // under DOS PSP segment
13. printf("nt Program's process identification");
14. printf(" number is : %X",getpid());
15. getch();
16. return 0;
17. }
Ou tput :
1. Program's process identification number (PID) number is : 8E01_
7. Conio.h header file in C:-
LIST OF INBUILT C FUNCTIONS IN CONIO.H FILE:
Functions Description
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
List of solved programs of 'conio.h' header file
1. clrscr() and delline() functions of conio.h in C.
In this article, we are going to learn about the two very useful functions clrscr() and delline() of conio.h header file
in C programming language.
2. getch() and getche() functions of conio.h in C.
In this article, we are going to learn about the pre-defined functions getch() and getche() of conio.h header file
and use them with the help of their examples.
3. gotoxy() and kbhit() functions of conio.h in C.
In this article, we are going to learn about the two rare pre-defined functions (gotoxy() and kbhit()) of conio.h
header file.
4. textcolor() and textbackground() functions of conio.h in C.
In this article, we are going to learn about the textbackground() and textcolor() functions of conio.h header file
and use them to change colors.
5. wherex()and wherey() functions of conio.h in C.
In this article, we are going to learn about the use of wherex() and wherey() functions of conio.h header file for
getting the position of cursor.
Some of these functions are given as below:-
1. Clrscr( ) and delline( ):
#include <conio.h>
int main()
{
// message on screen
printf("To clear the screen press any key from keyboard.");
getch();
// to clear screen
clrscr();
// message after clearing the screen
printf("The previous screen is now cleared.n");
printf("To get exit from the code just press any key.");
getch();
return 0;
}
Output
conio.h - delline() function Example in C:- deletes a line:-
When you are working on the console, you should always keep it clean and sober. The first thing we should do is
to clear the whole console when the program starts at the beginning. To accomplish this task all you need to do
is use clrscr() function at starting.
What clrscr() function does? It removes everything from the console and we get a clean console window ready
to use.
When you do not want to clear the whole screen? May be, we only want to delete a single line or multiple lines.
The Function delline() delete the current cursor line from the console. (Check the example given below for more
clarification).
We can say delline() is an abbreviation for Delete Line. This can be very useful when you want to bring
something up, because all you will need to do is raise your cursor up and delete those lines. Which in turn brings
up the matter up.
#include <stdio.h>
//to use delline() function
#include <conio.h>
int main()
{
// single line message
printf("To delete this line just press any key from keyboard.");
getch();
// calling function
delline();
// print the message after the code run successfully
printf("The line is deleted now.");
getch();
return 0;
}
Ouput
2. getch() function is used, to take a single byte of input from a user. We don’t care about the
input anyway, all we want is, that user should get some time to read or the window should wait
till the user wants it to be there. When the user presses any key on the keyboard the function
ends and the program ends.
The getche() function is almost similar but the little wider as it take any character or alphanumeric input. But the
different thing it does, is it prints out the input that the user has given.
Program already done in class.
4. textcolor() and textbackground() functions of conio.h in C.
In this article, we are going to learn about the textbackground() and textcolor() functions of conio.h
header file and use them to change colors.
These are very helpful functions to change the color or the background of the text. How this works is first we got
to set the color of the text and then print something on the console?
To use the textbackground()function all you need to do is before printing any text call this function with a
parameter defining the color in capital letters. That will be enough to change the background color of the text.
Now, if you want your text to blink then while calling the textcolor() function pass the color and also
say BLINK. This will like this: textcolor(BLUE+BLINK).
These are the function of the conio.h fileand must be included in your program.
conio.h - textbackground() function Example in C
#include <stdio.h>
//to use 'textbackground'
#include <conio.h>
int main()
{
// setting the color of background
textbackground(GREEN);
// message
cprintf("Change the background color to green");
getch();
return 0;
}
Output
conio.h - textcolor() function Example in C
#include <stdio.h>
//to use 'textcolor()'
#include <conio.h>
int main()
{
// set the color of text
textcolor(BLUE);
// message
cprintf("Color of text is BLUEnn");
// set blinking color
textcolor(GREEN+BLINK);
// message
cprintf("nThis is BLINKING text");
getch();
return 0;
}
Output
1.
UNIT 4-HEADER FILES IN C

Mais conteúdo relacionado

Mais procurados (20)

C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Looping Statement And Flow Chart
 Looping Statement And Flow Chart Looping Statement And Flow Chart
Looping Statement And Flow Chart
 
Python
PythonPython
Python
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
File handling in C
File handling in CFile handling in C
File handling in C
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Functions in C
Functions in CFunctions in C
Functions in C
 

Semelhante a UNIT 4-HEADER FILES IN C

C programming session 08
C programming session 08C programming session 08
C programming session 08Dushmanta Nath
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptxJawadTanvir
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4MKalpanaDevi
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib웅식 전
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxfaithxdunce63732
 
Presention programming
Presention programmingPresention programming
Presention programmingsaleha iqbal
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c languageHarish Gyanani
 
headerfilesinc-181121134545 (1).pdf
headerfilesinc-181121134545 (1).pdfheaderfilesinc-181121134545 (1).pdf
headerfilesinc-181121134545 (1).pdfjazzcashlimit
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.pptatulchaudhary821
 

Semelhante a UNIT 4-HEADER FILES IN C (20)

C programming session 08
C programming session 08C programming session 08
C programming session 08
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
7 functions
7  functions7  functions
7 functions
 
Tut1
Tut1Tut1
Tut1
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Structures-2
Structures-2Structures-2
Structures-2
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
 
Presention programming
Presention programmingPresention programming
Presention programming
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
 
headerfilesinc-181121134545 (1).pdf
headerfilesinc-181121134545 (1).pdfheaderfilesinc-181121134545 (1).pdf
headerfilesinc-181121134545 (1).pdf
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 

Mais de Raj vardhan

Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3Raj vardhan
 
Internet Basics Unit-7
Internet Basics  Unit-7Internet Basics  Unit-7
Internet Basics Unit-7Raj vardhan
 
Local Area Network – Wired LAN
Local Area Network – Wired LANLocal Area Network – Wired LAN
Local Area Network – Wired LANRaj vardhan
 
Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5Raj vardhan
 
Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture Raj vardhan
 
UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices Raj vardhan
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteUnit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteRaj vardhan
 
Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2Raj vardhan
 
Swachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project ReportSwachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project ReportRaj vardhan
 
Network Topology
Network TopologyNetwork Topology
Network TopologyRaj vardhan
 
Microsoft Office Word Introduction Complete
Microsoft Office Word  Introduction CompleteMicrosoft Office Word  Introduction Complete
Microsoft Office Word Introduction CompleteRaj vardhan
 
Digital money Revolution Introduction
Digital money Revolution IntroductionDigital money Revolution Introduction
Digital money Revolution IntroductionRaj vardhan
 
Definition of Business
Definition of BusinessDefinition of Business
Definition of BusinessRaj vardhan
 
Business Terms & Concepts
Business Terms & ConceptsBusiness Terms & Concepts
Business Terms & ConceptsRaj vardhan
 
Number System Conversion | BCA
Number System Conversion | BCANumber System Conversion | BCA
Number System Conversion | BCARaj vardhan
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FITRaj vardhan
 
FIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCAFIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCARaj vardhan
 
Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205 Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205 Raj vardhan
 
UNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCAUNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCARaj vardhan
 

Mais de Raj vardhan (20)

Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3Software Testing Life Cycle Unit-3
Software Testing Life Cycle Unit-3
 
Internet Basics Unit-7
Internet Basics  Unit-7Internet Basics  Unit-7
Internet Basics Unit-7
 
Local Area Network – Wired LAN
Local Area Network – Wired LANLocal Area Network – Wired LAN
Local Area Network – Wired LAN
 
Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5Network Connecting Devices UNIT 5
Network Connecting Devices UNIT 5
 
Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture Wireless LANs(IEEE802.11) Architecture
Wireless LANs(IEEE802.11) Architecture
 
UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices UNIT -03 Transmission Media and Connecting Devices
UNIT -03 Transmission Media and Connecting Devices
 
Unit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 CompleteUnit 1: Introduction to DBMS Unit 1 Complete
Unit 1: Introduction to DBMS Unit 1 Complete
 
Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2Introduction To Software Concepts Unit 1 & 2
Introduction To Software Concepts Unit 1 & 2
 
Swachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project ReportSwachh Bharat Abhiyan - Project Report
Swachh Bharat Abhiyan - Project Report
 
Network Topology
Network TopologyNetwork Topology
Network Topology
 
Microsoft Office Word Introduction Complete
Microsoft Office Word  Introduction CompleteMicrosoft Office Word  Introduction Complete
Microsoft Office Word Introduction Complete
 
Digital money Revolution Introduction
Digital money Revolution IntroductionDigital money Revolution Introduction
Digital money Revolution Introduction
 
C Programming
C ProgrammingC Programming
C Programming
 
Definition of Business
Definition of BusinessDefinition of Business
Definition of Business
 
Business Terms & Concepts
Business Terms & ConceptsBusiness Terms & Concepts
Business Terms & Concepts
 
Number System Conversion | BCA
Number System Conversion | BCANumber System Conversion | BCA
Number System Conversion | BCA
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FIT
 
FIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCAFIT-MS-WORD Lab | BCA
FIT-MS-WORD Lab | BCA
 
Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205 Syllabus Front End Design Tool VB.NET | BCA-205
Syllabus Front End Design Tool VB.NET | BCA-205
 
UNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCAUNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCA
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

UNIT 4-HEADER FILES IN C

  • 1. UNIT 4-HEADER FILES IN C A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. Typesof Header files  Sy stem header files: It iscomes withcompiler.  User headerfiles: It is written by programmer. You request to use a header file in your program by including it with the C preprocessing directive #include, like you have seen inclusion of stdio.hheader file, which comes along with your compiler. Including a header file is equal to copying the content of the header file but we do not do it because it will be error-prone and it is not a good idea to copy the content of a header file in the source files, especially if we have multiple source files in a program. A simple practice in C or C++ programs is that we keep all the constants, macros, system wide global variables, and function prototypes in the header files and include that header file wherever it is required. 1. math.h header file in C:- Function De s cr iption Exam ple sqrt(x) square root of x sqrt(4.0) is 2.0 sqrt(10.0) is 3.162278 exp(x) exponential (ex ) exp(1.0) is 2.718282 exp(4.0) is 54.598150 log(x) natural logarithm of x (base e) log(2.0) is 0.693147 log(4.0) is 1.386294 log10(x) logarithm of x (base 10) log10(10.0) is 1.0 log10(100.0) is 2.0
  • 2. Function De s cr iption Exam ple fabs(x) absolute value of x fabs(2.0) is 2.0 fabs(-2.0) is 2.0 ceil(x) rounds x to smallest integer not less than x ceil(9.2) is 10.0 ceil(-9.2) is -9.0 floor(x) rounds x to largest integer not greater than x floor(9.2) is 9.0 floor(-9.2) is -10.0 pow (x,y) x raised to pow er y (xy ) pow (2,2) is 4.0 fmod(x) remainder of x/y as floating-point number fmod(13.657, 2.333) is 1.992 sin(x) sine of x (x in radian) sin(0.0) is 0.0 cos(x) cosine of x (x in radian) cos(0.0) is 1.0 tan(x) tangent of x (x in radian) tan(0.0) is 0.0 Examples:-  SUBMIT #include <stdio.h> #include <math.h> int main() {
  • 3. printf("%fn",sqrt(10.0)); printf("%fn",exp(4.0)); printf("%fn",log(4.0)); printf("%fn",log10(100.0)); printf("%fn",fabs(-5.2)); printf("%fn",ceil(4.5)); printf("%fn",floor(-4.5)); printf("%fn",pow(4.0,.5)); printf("%fn",fmod(4.5,2.0)); printf("%fn",sin(0.0)); printf("%fn",cos(0.0)); printf("%fn",tan(0.0)); return 0; } Output 3.162278 54.598150 1.386294 2.000000 5.200000 5.000000 -5.000000 2.000000 0.500000 0.000000 1.000000 0.000000 2. ctype.hheaderfile inC:- ctype.h header file contains the functions related to characters. Some of the useful library functions are: isalnum(), isalpha(), isdigit(), isspace(), ispunct(), toupper(), tolower(). List of ctype.h header file’s libraryfunctions with explanation and example programs 1) isalnum() This function checks whether character is alphanumeric or not. 1 2 3 4 5 6 7 8 9 /* C example program of isalnum().*/ #include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c",&ch);
  • 4. 10 11 12 13 14 15 16 17 18 if(isalnum(ch)) printf("%c is an alphanumeric character.n",ch); else printf("%c is not an alphanumeric character.n",ch); return 0; } First run: Enter a character: H H is an alphanumeric character. Second run: Enter a character: % % is not an alphanumeric character. 2) isalpha() This function checks whether character is alphabet or not. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /* C example program of isalpha().*/ #include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c",&ch); if(isalpha(ch)) printf("%c is an alphabet.n",ch); else printf("%c is not an alphabet.n",ch); return 0; } First run: Enter a character: Y Y is an alphabet. Second run: Enter a character: 9 9 is not an alphabet. 3) isdigit() This function checks whether character is digit or not. 1 2 /* C example program of isdigit().*/ #include<stdio.h>
  • 5. 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include<ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c",&ch); if(isdigit(ch)) printf("%c is a digit.n",ch); else printf("%c is not a digit.n",ch); return 0; } First run: Enter a character: Y Y is not a digit. Second run: Enter a character: 9 9 is a digit. 4) isspace() This function checks whether character is space or not. 5) isupper() This function checks whether character is an uppercase character or not. 6) islower() This function checks whether character is a lowercase character or not. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 /* C example program of isspace(), isupper(), islower() .*/ #include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c",&ch); if(isupper(ch)) printf("%c is an uppercase character.n",ch); else if(islower(ch)) printf("%c is an lowercase character.n",ch); else if(isspace(ch)) printf("%c is space.n",ch); else
  • 6. 17 18 19 20 21 22 printf("%c is none from uppercase, lowercase and space.n",ch); return 0; } First run: Enter a character: T T is an uppercase character. Second run: Enter a character: t t is an lowercase character. Third run: Enter a character: main m is an lowercase character. Fourth run: Enter a character: is space. Fifth run: Enter a character: * * is none from uppercase, lowercase and space. 7) ispunct() This function checks whether character is a punctuation character or not. Punctuation characters are , . : ; ` @ # $ % ^ & * ( ) < > [ ] / { } ! | ~ - _ + ? = ' " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /* C example program of ispunct() .*/ #include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c",&ch); if(ispunct(ch)) printf("%c is a punctuation character.n",ch); else printf("%c is not a punctuation character.n",ch); return 0; } First run: Enter a character: ! ! is a punctuation character. Second run: Enter a character: ,
  • 7. , is a punctuation character. Third run: Enter a character: + + is a punctuation character. 8) isprint() This function checks whether character is printable or not. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /* C example program of ispunct() .*/ #include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c",&ch); if(isprint(ch)) printf("%c is a printable character.n",ch); else printf("%c is not a printable character.n",ch); return 0; } Enter a character: x x is a printable character. 9) toupper() This function returns character in upper case. 10) tolower() This function returns character in lower case. 1 2 3 4 5 6 7 8 9 10 11 /* C example program of toupper() and tolower() .*/ #include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character: "); scanf("%c",&ch); printf("Upper case: %c, Lower case: %cn",toupper(ch),tolower(ch));
  • 8. 12 13 14 15 return 0; } First run: Enter a character: w Upper case: W, Lower case: w Second run: Enter a character: 9 Upper case: 9, Lower case: 9 3. stdio.hheaderfile libraryfunctionsinC:- 1. perror() function of stdio.h in C. In this article, we are going to learn about the perror() function of stdio.h header file in C programming language, and use it prints a descriptive error message to stderr. 2. puts() and putchar() functions of stdio.h in C. In this article, we are going to learn about the putchar() and puts() function of stdio.h header file in C programming language and use it put string and characters on console. 3. gets() function of stdio.h in C. In this article, we are going to learn about the gets() function of stdio.h header file in C programming language, and use it get string and then print it on console. 4. putc() function of stdio.h in C. In this article, we are going to learn about the putc() function of stdio.h header file in C programming language, and use it to put characters inside a file with the help of file pointer. 5. fgets() function of stdio.h in C. In this article, we are going to learn about the fgets() function of stdio.h header file in C programming language and use it while getting the characters from file pointer. 6. fscanf() function of stdio.h in C. In this article, we are going to learn about the fscanf() function of stdio.h header file in C programming language and use it to scan rewind variables. Explainationswithexamples:- 1) perror() function in C:- This function is very useful as it prints the error message on the screen. All we have to do is if you have a situation where we caught an error; call this function with a parameter of string. The String which will be printed first, a colon, a space then the error message. Example: perror("here is the error"); will print → here is the error : ERROR MESSAGE. stdio.h - perror() function Example in C #include <stdio.h> int main ()
  • 9. { // defining the file pointer FILE *f; // rename file name rename("abc.txt", "abcd.txt"); // open file f = fopen("file.txt", "r"); // condition if error then print error if( f == NULL ) { perror("Error in Code is: "); return(-1); } // close the file fclose(f); return(0); } Output 2) puts( ) and putchar( ) functions:- The function puts() is used to print strings while putchar() function is used to print character as their names specifies. These functions are from the stdio.h class doing the jobs related to strings. Example: puts("I AM A STRING"); Output: I AM A STRING putchar("a"); Output: a You can also use printf() which havemore options then these two functions. #include <stdio.h> #include <string.h> int main () {
  • 10. // initializing the variables char a[15]; char b[15]; char c; // coming string in a and b strcpy(a, "includehelp"); strcpy(b, "ihelp"); // put a and b puts(a); puts(b); // printing characters for(c = 'Z' ; c >= 'A' ; c--) { putchar(c); } return(0); } Output 3) gets( ) in C:- The function gets() is used to scan a string from the user without any n or till the n character. This function is from the string.h class doing the jobs related to strings. Example: gets(str) ; User input: "I AM A STRING" Output: I AM A STRING You can also use scanf() which shavemore options then this function. stdio.h - gets() function Example in C
  • 11. #include <stdio.h> int main () { //initializing the type of variables char str[50]; char c; //message for user printf("Please enter a string : "); gets(str); //printing the result printf("Your String: %snn", str); //message for user printf("Please enter a character: "); c = getchar(); //printing the result printf("Your Character: "); putchar(c); return(0); } Output 4) putc( ) in C:- If you are handling files in your application then coping one file into other or from the same file will something you will encounter. Therefore, using the function putc() will help you doing this. The Function is use to write a single character in file. TheFunction needs only two parameters first a character and second is the file itself. Example: putc('a', FILE);
  • 12. //Here, FILE is the file variable. Output: It will write 'a' on the file at the current position of the cursor. Examplesalreadydone inclass. 5) fgets( ) inC:- If you are handling files in your application then reading from a file is something that you cannot ignore. Therefore, the function fgets() will help you doing this. The Function is use to read a string from a file. The Function needs only three parameters, first a character array, second is the number of character you want to read and the third is the file itself. Example: fgets (str, 60, F); //Here, str is a character array, F is the file variable. It will read 60 characters from the file from the current position of the cursor. stdio.h - fgets() function Example in C #include <stdio.h> int main () { //initializing the file pointer //and type of variables FILE *F; char str[60]; //open file abc in read mode F = fopen("abc.txt" , "r"); if(F == NULL) { perror("Error is:"); return(-1); } if( fgets (str, 60, F)!=NULL ) { //printing the output on console puts(str); } fclose(F); return(0); } Output
  • 13. 6) fscanf( ) in C:- This function is just like scanf() function, but instead of standard input, this read data from the file. Using this function is simple if you already knew about the scanf() function. This, fscanf() function requires one more parameter then the scanf() function and that parameter is the File object. Rest of the argument are just as the scanf() function. Syntax: fscanf(F, "%s", a); Here, F is the file object, a is the character array and "%s" string denoting the input value must be string. This will read a string from the file from the current position of the cursor. You can do same with integers etc. 4. stdlib.h library functions in C:- LIST OF INBUILT C FUNCTIONS IN STDLIB.H FILE: Function Description malloc() This function is used to allocate space in memory during the execution ofthe 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 ofan integer . The absolute value ofa number is always positive. Only integer values are supported in C.
  • 14. div() This function performs division operation abort() It terminates the C program exit() This function terminates the programand 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 ofthe 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 randominteger numbers delay() This function Suspends the execution ofthe programfor particular time a) atof():- Converts the string str to a decimal. If there are any white-space characters at the beginning of the string str then they are skipped. For example, in the string " 123", white-space characters present at the beginning of the string will be skipped and the conversion will start from the character '1'. The conversion stops if there is a character which is not a number. For example, in the string "123a12", the conversion will stop after converting "123" as soon as it encounters the non-numeric character 'a'. If the string str doesn't form any valid floating-point number then 0.0 is returned. #include <stdio.h> #include <stdlib.h> int main () { char str[10] = "3.14"; printf("The value is %fn",atof(str)); return 0;
  • 15. } Output The value is 3.140000 b) atoi( ) in C:- Converts the string str to an integer. If there are any white-space characters at the beginning of the string str then they are skipped. For example, in the string " 123", white-space characters present at the beginning of the string will be skipped and the conversion will start from the character '1'. The conversion stops if there is a character which is not a number. For example, int the string, "123a12" the conversion will stop after converting "123" as soon as it encounters the non-numeric character 'a'. If the string str doesn't form any valid integer number then 0 is returned. #include <stdio.h> #include <stdlib.h> int main () { char str[10] = "55"; printf("The value is %dn",atoi(str)); return 0; } Output The value is 55 5. process.h library functions in C:- process.h’ is a header file which includes macros and declarations. These are especially u sed during work with thread and processes. There is no standard for process.h functions. They depend on compiler whichwe use. 1. Some of the standard member functions of process.h header files are, 2. __________________________________________________________ 3. Function Name Description 4. execle - It loads & executes new child process by 5. placing it in memory previously occupied by 6. the parent process. 7. spawnv - Parameters are passed as an array of pointers. 8. It loads & executes new child process. 9. getpid - It returns the process identifier. 10. execlp - It loads & executes a new child process by 11. placing it in memory previously occupied by 12. the parent process. EXAMPLE:- 1. /* Program to demonstrate process.h header file working. 2. Creation Date : 06 Nov 2010 07:43:10 PM 3. Author : www.technoexam.com [Technowell, Sangli] */ 4. 5. #include <stdio.h> 6. #include <conio.h> 7. #include <process.h> 8. 9. int main(void) 10. {
  • 16. 11. clrscr(); 12. // under DOS PSP segment 13. printf("nt Program's process identification"); 14. printf(" number is : %X",getpid()); 15. getch(); 16. return 0; 17. } Ou tput : 1. Program's process identification number (PID) number is : 8E01_ 7. Conio.h header file in C:- LIST OF INBUILT C FUNCTIONS IN CONIO.H FILE: Functions Description 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 List of solved programs of 'conio.h' header file 1. clrscr() and delline() functions of conio.h in C. In this article, we are going to learn about the two very useful functions clrscr() and delline() of conio.h header file in C programming language. 2. getch() and getche() functions of conio.h in C. In this article, we are going to learn about the pre-defined functions getch() and getche() of conio.h header file and use them with the help of their examples. 3. gotoxy() and kbhit() functions of conio.h in C. In this article, we are going to learn about the two rare pre-defined functions (gotoxy() and kbhit()) of conio.h header file. 4. textcolor() and textbackground() functions of conio.h in C. In this article, we are going to learn about the textbackground() and textcolor() functions of conio.h header file and use them to change colors. 5. wherex()and wherey() functions of conio.h in C. In this article, we are going to learn about the use of wherex() and wherey() functions of conio.h header file for getting the position of cursor. Some of these functions are given as below:- 1. Clrscr( ) and delline( ): #include <conio.h> int main() { // message on screen printf("To clear the screen press any key from keyboard."); getch();
  • 17. // to clear screen clrscr(); // message after clearing the screen printf("The previous screen is now cleared.n"); printf("To get exit from the code just press any key."); getch(); return 0; } Output conio.h - delline() function Example in C:- deletes a line:- When you are working on the console, you should always keep it clean and sober. The first thing we should do is to clear the whole console when the program starts at the beginning. To accomplish this task all you need to do is use clrscr() function at starting. What clrscr() function does? It removes everything from the console and we get a clean console window ready to use. When you do not want to clear the whole screen? May be, we only want to delete a single line or multiple lines. The Function delline() delete the current cursor line from the console. (Check the example given below for more clarification). We can say delline() is an abbreviation for Delete Line. This can be very useful when you want to bring something up, because all you will need to do is raise your cursor up and delete those lines. Which in turn brings up the matter up. #include <stdio.h> //to use delline() function #include <conio.h> int main() { // single line message printf("To delete this line just press any key from keyboard."); getch(); // calling function delline(); // print the message after the code run successfully printf("The line is deleted now.");
  • 18. getch(); return 0; } Ouput 2. getch() function is used, to take a single byte of input from a user. We don’t care about the input anyway, all we want is, that user should get some time to read or the window should wait till the user wants it to be there. When the user presses any key on the keyboard the function ends and the program ends. The getche() function is almost similar but the little wider as it take any character or alphanumeric input. But the different thing it does, is it prints out the input that the user has given. Program already done in class. 4. textcolor() and textbackground() functions of conio.h in C. In this article, we are going to learn about the textbackground() and textcolor() functions of conio.h header file and use them to change colors. These are very helpful functions to change the color or the background of the text. How this works is first we got to set the color of the text and then print something on the console? To use the textbackground()function all you need to do is before printing any text call this function with a parameter defining the color in capital letters. That will be enough to change the background color of the text. Now, if you want your text to blink then while calling the textcolor() function pass the color and also say BLINK. This will like this: textcolor(BLUE+BLINK). These are the function of the conio.h fileand must be included in your program. conio.h - textbackground() function Example in C #include <stdio.h> //to use 'textbackground' #include <conio.h> int main() { // setting the color of background textbackground(GREEN);
  • 19. // message cprintf("Change the background color to green"); getch(); return 0; } Output conio.h - textcolor() function Example in C #include <stdio.h> //to use 'textcolor()' #include <conio.h> int main() { // set the color of text textcolor(BLUE); // message cprintf("Color of text is BLUEnn"); // set blinking color textcolor(GREEN+BLINK); // message cprintf("nThis is BLINKING text"); getch(); return 0; } Output 1.