SlideShare a Scribd company logo
PAPER: INTRODUCTION PROGRAMMING LANGUAGE USING C
PAPER ID: 20105
PAPER CODE: BCA 105
DR. VARUN TIWARI
(ASSOCIATE PROFESSOR)
(DEPARTMENT OF COMPUTER SCIENCE)
BOSCO TECHNICAL TRAINING SOCIETY,
DON BOSCO TECHNICAL SCHOOL, OKHLA ROAD , NEW DELHI
STRING MANIPULATION FUNCTION
& C HEADER FILE FUNCTION
OBJECTIVES
IN THIS CHAPTER YOU WILL LEARN:
1. TO UNDERSTAND ABOUT STDIO.H IN C.
2. TO LEARN ABOUT MATH.H IN C.
3. TO LEARN ABOUT CTYPE.H IN C.
4. TO UNDERSTAND STDLIB.H IN C.
5. TO LEARN ABOUT CONIO.H IN C.
6. TO LEARN ABOUT STRING.H IN C.
7. TO LEARN ABOUT PROCESS.H IN C.
STDIO.H:
Function Description
printf()
It is used to print the character, string, float, integer, octal and
hexadecimal values onto the output screen.
scanf() It is used to read a character, string, numeric data from keyboard.
gets() It reads line from keyboard
puts() It writes line to output screen
fopen() fopen() is used to open a file in different mode
fclose() closes an opened file
getw() reads an integer from file
putw() writes an integer to file
EXAMPLE PRINTF AND SCANF
#include <stdio.h>
void main()
{
int a;
printf(“Enter any number-:");
scanf(“%d”,&a);
printf(“output is -:%d”,a);
}
EXAMPLE FOPEN AND FCLOSE
FOPEN FUNCTION IS USED TO OPENING A FILE IN DIFFERENT MODES AND FCLOSE FUNCTION IS USED
TO CLOSING A FILE.
#include<stdio.h>
void main(){
FILE *a;
a = fopen("file.txt", "w");//opening file
fprintf(a, "Hello how r u.n");//writing data into file
fclose(a);//closing file
}
EXAMPLE GETS AND PUTS
GETS() FUNCTION IS USED TO READS STRING FROM USER AND PUTS() FUNCTION IS USED TO PRINT THE STRING.
#include<stdio.h>
#include<conio.h>
void main(){
char n[25];
clrscr();
printf("enter your name: ");
gets(n);
printf("your name is: ");
puts(n);
getch(); }
EXAMPLE OF GETW() AND PUTW()
GETW() FUNCTION IS USED TO READ A INTEGER VALUE FROM A FILE AND PUTW() IS USED TO WRITE AN INTEGER VALUE FROM A FILE.
#include <stdio.h>
void main () {
FILE *f;
int a,n;
clrscr();
f = fopen ("bcd1.txt","w");
for(a=1;a<=10;a++) {
putw(a,f); }
fclose(f);
f = fopen ("bcd1.txt","r");
while((n=getw(f))!=EOF)
{ printf("n Output is-: %d n", n);} fclose(f); getch(); }
MATH.H:
Function Function Description
ceil It returns nearest integer greater than argument passed.
cos It is used to computes the cosine of the argument
exp It is used to computes the exponential raised to given power
floor Returns nearest integer lower than the argument passed.
log Computes natural logarithm
log10 Computes logarithm of base argument 10
pow Computes the number raised to given power
sin Computes sine of the argument
sqrt Computes square root of the argument
tan Computes tangent of the argument
EXAMPLE OF CUBE() , CEIL() , EXP() AND COS()
#include <stdio.h> #include <math.h>
#define pi 3.1415
void main()
{ double n =4.6,a=24.0,res; clrscr();
res = ceil(n);
printf("n ceiling integer of %.2f = %.2f", n, res);
a = (a * pi) / 180;
res = cos(a);
printf("n cos value of is %lf radian = %lf", a, res);
res = exp(n);
printf("n exponential of %lf = %lf", n, res); getch(); }
EXAMPLE OF POW, LOG, FLOOR AND LOG10
#include <stdio.h>
#include <math.h>
void main()
{ double n = 4.7,p=-9.33,res,b=3,po=4; clrscr();
res = pow(b,po);
printf("n %lf ^ %lf = %lf", b, po, res);
res = log(n);
printf("n log value is %f = %f", n, res);
res = floor(p);
printf("n floor integer of %.2f = %.2f", p, res);
res = log10(n);
printf("n log10 value is %f = %f", n, res);
getch(); }
Example of sin(), sqrt() and tan() in c.
#include <stdio.h>
#include <math.h>
void main()
{ double n = 4.7,sr,res;
clrscr();
res = sin(n);
printf("n sin value is -: %lf = %lf", n, res);
sr = sqrt(n);
printf("n square root of %lf = %lf", n, sr);
res = tan(n);
printf("n tan value is -: %lf = %lf", n, res); getch(); }
CONIO.H:
Function Function Description
clrscr() This function is used to clear the output screen.
getch()
This function is used to hold the screen until any character not press from
keyboard
textcolor() This function is used to define text color.
textbackground() This function is used to define background color of the text.
getche() It is used to get a character from the console and echoes to the screen.
Example of getch(),getche()
void main()
{
char c;
int p;
printf( "Press any keyn" );
c = getche();
printf( "You pressed %c(%d)n", c, c );
c = getch();
printf("Input Char Is :%c",c);
getch();
}
Example of clrscr(), textcolor() and textbackground()
#include<conio.h>
void main()
{ int i;
clrscr();
for(i=0; i<=15; i++)
{ textcolor(i);
textbackground(10-i);
cprintf("Bosco Technical Training Society");
cprintf("rn"); }
getch(); }
CTYPE.H:
Function Function Description
isalnum Tests whether a character is alphanumeric or not
isalpha Tests whether a character is alphabetic or not
iscntrl Tests whether a character is control or not
isdigit Tests whether a character is digit or not
islower Tests whether a character is lowercase or not
ispunct Tests whether a character is punctuation or not
isspace Tests whether a character is white space or not
isupper Tests whether a character is uppercase or not
tolower Converts to lowercase if the character is in uppercase
toupper Converts to uppercase if the character is in lowercase
Example of iscntrl() , isdigit() , isupper(),
islower()
#include <stdio.h> #include <ctype.h>
void main() { char c='n';
char p; char q,r; clrscr();
if(iscntrl(c)) printf("n u entered control value"); else printf("n not a control character");
printf("n enter any numeric value"); scanf("%c",&p);
if(isdigit(p)) printf("n entered value is digit"); else printf("n not digit");
q='a'; if(islower(q)) printf("n entered value is lower"); else printf("n not lower");
printf("n");
r='p'; if(isupper(r)) printf("n entered value is upper"); else printf("n not upper");
getch();
}
Example of isalnum() , isalpha() , ispunct(),
isspace()
#include <stdio.h> #include <ctype.h>
void main() { char c='c'; char p;
char q,r; clrscr();
if(isalpha(c)) printf("n u entered alphabetic value"); else printf("n Not an Alphabet");
printf("n Enter any numeric value"); scanf("%c",&p); if(isalnum(p))
printf("n Entered value is alphanumeric"); else printf("n Not alphanumeric");
q=' '; if(isspace(q)) printf("n Space is here"); else printf("n Space is not here"); printf("n");
r=':'; if(ispunct(r)) printf("n Entered value is punctuation"); else printf("n Not Punctuation");
getch(); }
Example of ispunct() , isspace() , isupper(), tolower() and toupper()
#include <stdio.h>
#include <ctype.h>
void main()
{ char c;
c = 'M'; res = tolower(c); printf("tolower is -: %c = %c n",
c, res);
c = 'h'; res = toupper(c); printf("toupper is-: %c = %c n", c,
res);
getch();}
STRING.H:
Function Function Description
strlen() computes string's length
strcpy() copies a string to another
strcat() concatenates(joins) two strings
strcmp() compares two strings
strlwr() converts string to lowercase
strupr() converts string to uppercase
Example of all string function
#include <stdio.h> #include <string.h>
void main() {
char a[20]="java"; char b[20]="program"; char c[20]; int res,d,g;
char s1[] = "vivek", s2[] = "viVek", s3[] = "vivek"; char q[40];
clrscr(); d=strlen(a); g=strlen(b);
printf("n length is a-: %d",d);
printf("n length is b -%d",g); strcpy(a,c); puts(c); printf("n %s",strcat(a,b));
res = strcmp(s1, s2); printf("n strcmp(s1, s2) = %dn", res); res = strcmp(s1,
s3);
printf("n strcmp(s1, s3) = %dn", res); printf("n %s",strlwr(a)); printf("n
%s",strupr(b));
getch();
}
PROCESS.H:
Function Function Description
system() To run system command.
abort() Abort current process (function )
exit() Terminates the program
getpid() Get the process id of the program
Example of abort(),exit()
#include <stdio.h>
#include <stdlib.h>
void main () { FILE *f; f= fopen ("test.txt","r");
if (f == NULL) {
fputs ("error opening filen",stderr); abort(); } fclose (f); }
#include <stdio.h>
#include <stdlib.h>
void main ()
{ FILE *f; f = fopen ("test.txt","r");
if (f==NULL) { printf ("Error opening file"); exit (EXIT_FAILURE); } else
{ /* opening a file code here*/ }}
Example of system(),getpid()
#include <stdio.h>
#include <stdlib.h>
void main () {
system(“cls”);
system(“dir”);
printf(“n Process id of this program-: %X”,getpid());
getch();
}
STDLIB.H:
Function Function Description
atof Convert string to double (function )
atoi Convert string to integer (function )
atol Convert string to long integer (function )
rand Generate random number (function )
abort Abort current process (function )
Exit Terminates the program (function)
Example of atoi() , atol() , atof()
#include <stdio.h>
#include <stdlib.h>
void main ()
{ long int li;int i;
double n,m; double pi=3.141;
char buf[100];
printf ("enter degrees: ");
fgets (buf,100,stdin);
n = atof (buf);
m = sin (n*pi/180);
printf ("the sine of %f degrees is %fn" , n, m);
printf ("enter a long number: ");
li = atol(buf);
printf ("the value entered is %ld. its double is %ld.n",li,li*2);
i = atoi (buf);
printf ("the value entered is %d. its double is %d.n",i,i*2);
getch(); }
Example of abort(),exit()
#include <stdio.h>
#include <stdlib.h>
void main () { FILE *f; f= fopen ("test.txt","r");
if (f == NULL) {
fputs ("error opening filen",stderr); abort(); } fclose (f); }
#include <stdio.h>
#include <stdlib.h>
void main ()
{ FILE *f; f = fopen ("test.txt","r");
if (f==NULL) { printf ("Error opening file"); exit (EXIT_FAILURE); } else
{ /* opening a file code here*/ }}
Example of rand()
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main ()
{ int s,g;
srand (time(NULL));
s = rand() % 10 + 1;
do { printf ("Guess the number (1 to 10): ");
scanf ("%d",&g);
if (s<g) puts ("The secret number is lower");
else if (s>g) puts ("The secret number is higher");
} while (s!=g);
puts ("Hurrah your secret no is equal guess no");
return 0; }
THANK YOU

More Related Content

What's hot (20)

PDF
C++ Programming - 1st Study
Chris Ohk
 
PDF
Stl algorithm-Basic types
mohamed sikander
 
PPTX
C Programming Language Part 8
Rumman Ansari
 
PDF
C++ Question on References and Function Overloading
mohamed sikander
 
PDF
Bcsl 033 data and file structures lab s2-3
Dr. Loganathan R
 
PDF
Inheritance and polymorphism
mohamed sikander
 
PDF
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
rohit kumar
 
PDF
C++ Programming - 11th Study
Chris Ohk
 
DOC
C tech questions
vijay00791
 
PDF
Bcsl 033 data and file structures lab s2-2
Dr. Loganathan R
 
PPT
Functions and pointers_unit_4
MKalpanaDevi
 
PDF
C++ programs
Mukund Gandrakota
 
DOCX
C interview question answer 2
Amit Kapoor
 
PPTX
C Programming Language Part 7
Rumman Ansari
 
PDF
C++ Programming - 2nd Study
Chris Ohk
 
PDF
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
PDF
4 operators, expressions &amp; statements
MomenMostafa
 
PDF
CS50 Lecture4
昀 李
 
DOC
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Hazrat Bilal
 
C++ Programming - 1st Study
Chris Ohk
 
Stl algorithm-Basic types
mohamed sikander
 
C Programming Language Part 8
Rumman Ansari
 
C++ Question on References and Function Overloading
mohamed sikander
 
Bcsl 033 data and file structures lab s2-3
Dr. Loganathan R
 
Inheritance and polymorphism
mohamed sikander
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
rohit kumar
 
C++ Programming - 11th Study
Chris Ohk
 
C tech questions
vijay00791
 
Bcsl 033 data and file structures lab s2-2
Dr. Loganathan R
 
Functions and pointers_unit_4
MKalpanaDevi
 
C++ programs
Mukund Gandrakota
 
C interview question answer 2
Amit Kapoor
 
C Programming Language Part 7
Rumman Ansari
 
C++ Programming - 2nd Study
Chris Ohk
 
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
4 operators, expressions &amp; statements
MomenMostafa
 
CS50 Lecture4
昀 李
 
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Hazrat Bilal
 

Similar to String Manipulation Function and Header File Functions (20)

DOCX
UNIT 4-HEADER FILES IN C
Raj vardhan
 
PPTX
Header file.pptx
ALANWALKERPIANO
 
PDF
Fundamentals C programming and strong your skills.
GouravRana39
 
PDF
C for Java programmers (part 1)
Dmitry Zinoviev
 
PDF
Chapter 5
EasyStudy3
 
PPTX
Introduction to Basic C programming 02
Wingston
 
PPTX
c_pro_introduction.pptx
RohitRaj744272
 
PPTX
C language
Priya698357
 
PPTX
20220823094225_PPT02-Formatted Input and Output.pptx
putrielisabeth3
 
DOCX
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
PPT
Cbasic
rohitladdu
 
PPT
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
PPTX
presentation_c_basics_1589366177_381682.pptx
KrishanPalSingh39
 
PPTX
Programming in C Basics
Bharat Kalia
 
PPT
C chap08
teach4uin
 
PPTX
Input and Output In C Language
Adnan Khan
 
PPTX
Introduction to C Unit 1
Dr. SURBHI SAROHA
 
PPTX
C language
TaranjeetKaur72
 
UNIT 4-HEADER FILES IN C
Raj vardhan
 
Header file.pptx
ALANWALKERPIANO
 
Fundamentals C programming and strong your skills.
GouravRana39
 
C for Java programmers (part 1)
Dmitry Zinoviev
 
Chapter 5
EasyStudy3
 
Introduction to Basic C programming 02
Wingston
 
c_pro_introduction.pptx
RohitRaj744272
 
C language
Priya698357
 
20220823094225_PPT02-Formatted Input and Output.pptx
putrielisabeth3
 
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
Cbasic
rohitladdu
 
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
presentation_c_basics_1589366177_381682.pptx
KrishanPalSingh39
 
Programming in C Basics
Bharat Kalia
 
C chap08
teach4uin
 
Input and Output In C Language
Adnan Khan
 
Introduction to C Unit 1
Dr. SURBHI SAROHA
 
C language
TaranjeetKaur72
 
Ad

More from Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi) (20)

Ad

Recently uploaded (20)

PDF
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 

String Manipulation Function and Header File Functions

  • 1. PAPER: INTRODUCTION PROGRAMMING LANGUAGE USING C PAPER ID: 20105 PAPER CODE: BCA 105 DR. VARUN TIWARI (ASSOCIATE PROFESSOR) (DEPARTMENT OF COMPUTER SCIENCE) BOSCO TECHNICAL TRAINING SOCIETY, DON BOSCO TECHNICAL SCHOOL, OKHLA ROAD , NEW DELHI
  • 2. STRING MANIPULATION FUNCTION & C HEADER FILE FUNCTION
  • 3. OBJECTIVES IN THIS CHAPTER YOU WILL LEARN: 1. TO UNDERSTAND ABOUT STDIO.H IN C. 2. TO LEARN ABOUT MATH.H IN C. 3. TO LEARN ABOUT CTYPE.H IN C. 4. TO UNDERSTAND STDLIB.H IN C. 5. TO LEARN ABOUT CONIO.H IN C. 6. TO LEARN ABOUT STRING.H IN C. 7. TO LEARN ABOUT PROCESS.H IN C.
  • 4. STDIO.H: Function Description printf() It is used to print the character, string, float, integer, octal and hexadecimal values onto the output screen. scanf() It is used to read a character, string, numeric data from keyboard. gets() It reads line from keyboard puts() It writes line to output screen fopen() fopen() is used to open a file in different mode fclose() closes an opened file getw() reads an integer from file putw() writes an integer to file
  • 5. EXAMPLE PRINTF AND SCANF #include <stdio.h> void main() { int a; printf(“Enter any number-:"); scanf(“%d”,&a); printf(“output is -:%d”,a); }
  • 6. EXAMPLE FOPEN AND FCLOSE FOPEN FUNCTION IS USED TO OPENING A FILE IN DIFFERENT MODES AND FCLOSE FUNCTION IS USED TO CLOSING A FILE. #include<stdio.h> void main(){ FILE *a; a = fopen("file.txt", "w");//opening file fprintf(a, "Hello how r u.n");//writing data into file fclose(a);//closing file }
  • 7. EXAMPLE GETS AND PUTS GETS() FUNCTION IS USED TO READS STRING FROM USER AND PUTS() FUNCTION IS USED TO PRINT THE STRING. #include<stdio.h> #include<conio.h> void main(){ char n[25]; clrscr(); printf("enter your name: "); gets(n); printf("your name is: "); puts(n); getch(); }
  • 8. EXAMPLE OF GETW() AND PUTW() GETW() FUNCTION IS USED TO READ A INTEGER VALUE FROM A FILE AND PUTW() IS USED TO WRITE AN INTEGER VALUE FROM A FILE. #include <stdio.h> void main () { FILE *f; int a,n; clrscr(); f = fopen ("bcd1.txt","w"); for(a=1;a<=10;a++) { putw(a,f); } fclose(f); f = fopen ("bcd1.txt","r"); while((n=getw(f))!=EOF) { printf("n Output is-: %d n", n);} fclose(f); getch(); }
  • 9. MATH.H: Function Function Description ceil It returns nearest integer greater than argument passed. cos It is used to computes the cosine of the argument exp It is used to computes the exponential raised to given power floor Returns nearest integer lower than the argument passed. log Computes natural logarithm log10 Computes logarithm of base argument 10 pow Computes the number raised to given power sin Computes sine of the argument sqrt Computes square root of the argument tan Computes tangent of the argument
  • 10. EXAMPLE OF CUBE() , CEIL() , EXP() AND COS() #include <stdio.h> #include <math.h> #define pi 3.1415 void main() { double n =4.6,a=24.0,res; clrscr(); res = ceil(n); printf("n ceiling integer of %.2f = %.2f", n, res); a = (a * pi) / 180; res = cos(a); printf("n cos value of is %lf radian = %lf", a, res); res = exp(n); printf("n exponential of %lf = %lf", n, res); getch(); }
  • 11. EXAMPLE OF POW, LOG, FLOOR AND LOG10 #include <stdio.h> #include <math.h> void main() { double n = 4.7,p=-9.33,res,b=3,po=4; clrscr(); res = pow(b,po); printf("n %lf ^ %lf = %lf", b, po, res); res = log(n); printf("n log value is %f = %f", n, res); res = floor(p); printf("n floor integer of %.2f = %.2f", p, res); res = log10(n); printf("n log10 value is %f = %f", n, res); getch(); }
  • 12. Example of sin(), sqrt() and tan() in c. #include <stdio.h> #include <math.h> void main() { double n = 4.7,sr,res; clrscr(); res = sin(n); printf("n sin value is -: %lf = %lf", n, res); sr = sqrt(n); printf("n square root of %lf = %lf", n, sr); res = tan(n); printf("n tan value is -: %lf = %lf", n, res); getch(); }
  • 13. CONIO.H: Function Function Description clrscr() This function is used to clear the output screen. getch() This function is used to hold the screen until any character not press from keyboard textcolor() This function is used to define text color. textbackground() This function is used to define background color of the text. getche() It is used to get a character from the console and echoes to the screen.
  • 14. Example of getch(),getche() void main() { char c; int p; printf( "Press any keyn" ); c = getche(); printf( "You pressed %c(%d)n", c, c ); c = getch(); printf("Input Char Is :%c",c); getch(); }
  • 15. Example of clrscr(), textcolor() and textbackground() #include<conio.h> void main() { int i; clrscr(); for(i=0; i<=15; i++) { textcolor(i); textbackground(10-i); cprintf("Bosco Technical Training Society"); cprintf("rn"); } getch(); }
  • 16. CTYPE.H: Function Function Description isalnum Tests whether a character is alphanumeric or not isalpha Tests whether a character is alphabetic or not iscntrl Tests whether a character is control or not isdigit Tests whether a character is digit or not islower Tests whether a character is lowercase or not ispunct Tests whether a character is punctuation or not isspace Tests whether a character is white space or not isupper Tests whether a character is uppercase or not tolower Converts to lowercase if the character is in uppercase toupper Converts to uppercase if the character is in lowercase
  • 17. Example of iscntrl() , isdigit() , isupper(), islower() #include <stdio.h> #include <ctype.h> void main() { char c='n'; char p; char q,r; clrscr(); if(iscntrl(c)) printf("n u entered control value"); else printf("n not a control character"); printf("n enter any numeric value"); scanf("%c",&p); if(isdigit(p)) printf("n entered value is digit"); else printf("n not digit"); q='a'; if(islower(q)) printf("n entered value is lower"); else printf("n not lower"); printf("n"); r='p'; if(isupper(r)) printf("n entered value is upper"); else printf("n not upper"); getch(); }
  • 18. Example of isalnum() , isalpha() , ispunct(), isspace() #include <stdio.h> #include <ctype.h> void main() { char c='c'; char p; char q,r; clrscr(); if(isalpha(c)) printf("n u entered alphabetic value"); else printf("n Not an Alphabet"); printf("n Enter any numeric value"); scanf("%c",&p); if(isalnum(p)) printf("n Entered value is alphanumeric"); else printf("n Not alphanumeric"); q=' '; if(isspace(q)) printf("n Space is here"); else printf("n Space is not here"); printf("n"); r=':'; if(ispunct(r)) printf("n Entered value is punctuation"); else printf("n Not Punctuation"); getch(); }
  • 19. Example of ispunct() , isspace() , isupper(), tolower() and toupper() #include <stdio.h> #include <ctype.h> void main() { char c; c = 'M'; res = tolower(c); printf("tolower is -: %c = %c n", c, res); c = 'h'; res = toupper(c); printf("toupper is-: %c = %c n", c, res); getch();}
  • 20. STRING.H: Function Function Description strlen() computes string's length strcpy() copies a string to another strcat() concatenates(joins) two strings strcmp() compares two strings strlwr() converts string to lowercase strupr() converts string to uppercase
  • 21. Example of all string function #include <stdio.h> #include <string.h> void main() { char a[20]="java"; char b[20]="program"; char c[20]; int res,d,g; char s1[] = "vivek", s2[] = "viVek", s3[] = "vivek"; char q[40]; clrscr(); d=strlen(a); g=strlen(b); printf("n length is a-: %d",d); printf("n length is b -%d",g); strcpy(a,c); puts(c); printf("n %s",strcat(a,b)); res = strcmp(s1, s2); printf("n strcmp(s1, s2) = %dn", res); res = strcmp(s1, s3); printf("n strcmp(s1, s3) = %dn", res); printf("n %s",strlwr(a)); printf("n %s",strupr(b)); getch(); }
  • 22. PROCESS.H: Function Function Description system() To run system command. abort() Abort current process (function ) exit() Terminates the program getpid() Get the process id of the program
  • 23. Example of abort(),exit() #include <stdio.h> #include <stdlib.h> void main () { FILE *f; f= fopen ("test.txt","r"); if (f == NULL) { fputs ("error opening filen",stderr); abort(); } fclose (f); } #include <stdio.h> #include <stdlib.h> void main () { FILE *f; f = fopen ("test.txt","r"); if (f==NULL) { printf ("Error opening file"); exit (EXIT_FAILURE); } else { /* opening a file code here*/ }}
  • 24. Example of system(),getpid() #include <stdio.h> #include <stdlib.h> void main () { system(“cls”); system(“dir”); printf(“n Process id of this program-: %X”,getpid()); getch(); }
  • 25. STDLIB.H: Function Function Description atof Convert string to double (function ) atoi Convert string to integer (function ) atol Convert string to long integer (function ) rand Generate random number (function ) abort Abort current process (function ) Exit Terminates the program (function)
  • 26. Example of atoi() , atol() , atof() #include <stdio.h> #include <stdlib.h> void main () { long int li;int i; double n,m; double pi=3.141; char buf[100]; printf ("enter degrees: "); fgets (buf,100,stdin); n = atof (buf); m = sin (n*pi/180); printf ("the sine of %f degrees is %fn" , n, m); printf ("enter a long number: "); li = atol(buf); printf ("the value entered is %ld. its double is %ld.n",li,li*2); i = atoi (buf); printf ("the value entered is %d. its double is %d.n",i,i*2); getch(); }
  • 27. Example of abort(),exit() #include <stdio.h> #include <stdlib.h> void main () { FILE *f; f= fopen ("test.txt","r"); if (f == NULL) { fputs ("error opening filen",stderr); abort(); } fclose (f); } #include <stdio.h> #include <stdlib.h> void main () { FILE *f; f = fopen ("test.txt","r"); if (f==NULL) { printf ("Error opening file"); exit (EXIT_FAILURE); } else { /* opening a file code here*/ }}
  • 28. Example of rand() #include <stdio.h> #include <stdlib.h> #include <time.h> void main () { int s,g; srand (time(NULL)); s = rand() % 10 + 1; do { printf ("Guess the number (1 to 10): "); scanf ("%d",&g); if (s<g) puts ("The secret number is lower"); else if (s>g) puts ("The secret number is higher"); } while (s!=g); puts ("Hurrah your secret no is equal guess no"); return 0; }