Library Functions

Introduction

Generallyreferstothefunctionsprovidedbythecompilerthatcanbecalledinthecsourceprogram.Canbedividedintotwocategories,oneisthelibraryfunctionspecifiedbytheClanguagestandard,andtheotheristhelibraryfunctionspecifictothecompiler.

Duetocopyrightreasons,thesourcecodeoflibraryfunctionsisgenerallyinvisible,butyoucanseetheintroductionofitsexternalinterfacelibraryfunctionsintheheaderfile.

TheClanguagestatementisverysimple.IfyouwanttousetheClanguagestatementtodirectlycalculatethesinorcosfunction,youneedtowritearathercomplicatedprogram.BecausetheClanguagestatementdoesnotprovideastatementthatdirectlycalculatesthesinorcosfunction.Anotherexampleistodisplayaparagraphoftext,wecannotfindthedisplaystatementintheClanguage,wecanonlyusethelibraryfunctionprintf.

ThelibraryfunctionsoftheClanguagearenotpartoftheClanguageitself.Itisasetofprogramscompiledandprovidedbythecompileraccordingtotheneedsofgeneralusers.TheClibraryfunctionsgreatlyfacilitateusers,andatthesametimesupplementthedeficienciesoftheClanguageitself.Infact,whenwritingClanguageprograms,libraryfunctionsshouldbeusedasmuchaspossible,sothatboththeefficiencyoftheprogramandthequalityofprogrammingcanbeimproved.

Thestaticlibraryiscalledhere.

Basicconcepts

Functionlibrary:Thefunctionlibraryisacollectionoffunctionswithcertainfunctionsestablishedbythesystem.Thenameofthefunctionandthecorrespondingobjectcodearestoredinthelibrary,aswellastherelocationinformationrequiredduringtheconnectionprocess.Userscanalsobuildtheirownuserfunctionlibraryaccordingtotheirneeds.

Libraryfunctions:functionsstoredinthefunctionlibrary.Libraryfunctionshaveclearfunctions,entrycallparametersandreturnvalues.

Linkprogram:Linktheobjectfilesgeneratedbythecompilertogenerateanexecutablefile.

Headerfiles:Sometimescalledincludefiles.ThedataandvariablestobeusedforinformationcommunicationbetweentheClanguagelibraryfunctionandtheuserprogram.Whenusingalibraryfunction,theheaderfilecorrespondingtothefunctionmustbeembedded(using#include)intheprogram.

BecausethereisnointernationalstandardforthefunctionlibrarythattheClanguagecompilationsystemshouldprovide.DifferentversionsoftheClanguagehavedifferentlibraryfunctions,andusersshouldrefertothelibraryfunctionreferencemanualoftherelevantversionofCwhenusingit.Let'stakeTurboC?asanexampletointroducethelibraryfunctionsofC,andsomecommonlyusedlibraryfunctionsofTurboCaregivenintheappendix.

Ninecategories

(1)I/Ofunctions.IncludingvariousconsoleI/O,bufferedfileI/OandUNIX-styleunbufferedfileI/Ooperations.

Requiredincludefile:stdio.h

Forexample:getchar,putchar,printf,scanf,fopen,fclose,fgetc,fgets,fprintf,fsacnf,fputc,fputs,fseek,fread,fwrite,etc.

(2)String,memoryandcharacterfunctions.Includingfunctionsforperformingvariousoperationsonstringsandperformingoperationsoncharacters.

Requiredincludefiles:string.h,mem.h,ctype.h,orstring.h

Forexample:functionsforcheckingcharacters:isalnum,isalpha,isdigit,islower,Isspace,etc.?Functionsforstringmanipulation:strcat,strchr,strcmp,strcpy,strlen,strstr,etc.

(3)Mathematicalfunctions.Includingvariouscommonlyusedtrigonometricfunctions,hyperbolicfunctions,exponentialandlogarithmicfunctions,etc.

Needincludefile:math.h

Forexample:sin,cos,exp(etothepowerofx),log,sqrt(squareroot),pow(xofyPower)andsoon.

(4)Time,dateandsystem-relatedfunctions.Operationoftimeanddateandsettingofcomputersystemstatus,etc.

Requiredincludefile:time.h

Forexample:timereturnsthetimeofthesystem;asctimereturnsthedateandtimeintheformofastring.

(5)Dynamicstorageallocation.Includingthefunctionsof"applicationforallocation"and"release"ofmemoryspace.

Requiredincludefiles:alloc.horstdlib.h

Forexample:calloc,free,malloc,realloc,etc.

(6)Directorymanagement.Includingfunctionsforcreating,querying,andchangingthediskdirectory.

(7)Processcontrol.Includingthemostbasicprocesscontrolfunctions.

(8)Characterscreenandgraphicfunctions.Includingvariousfunctionsfordrawingpoints,lines,circles,squaresandcoloring.

(9)Otherfunctions.

Content

①Thefunctionofthefunctionandtheoperationsitcancomplete

②Thenumberandorderoftheparameters,aswellasthemeaningandtypeofeachparameter

③Themeaningandtypeofthereturnvalue

④Theincludefilethatneedstobeused

Thisisanecessaryconditionforthecorrectuseoflibraryfunctions.

Relateddifferences

(1)Libraryfunctionsarepartofthelanguageorapplicationprogram,whilesystemcallsaretheinterfaceprovidedbythekerneltotheapplicationprogram,andarepartofthesystem

(2)Libraryfunctionsareexecutedintheuseraddressspace,systemcallsareexecutedinthekerneladdressspace,libraryfunctionrunningtimebelongstousertime,systemcallsbelongtosystemtime,libraryfunctionoverheadissmall,andsystemcalloverheadislarge

(3)Libraryfunctionsarebuffered,systemcallsareunbuffered

(4)Systemcallsdependontheplatform,libraryfunctionsdonotdependon

Built-infunctionsLibrary

1.TherelationshipbetweenClanguageandClanguagelibraryfunctionsissimilartotherelationshipbetweenChinesecharactersandclassicworks.Clanguageisacomputerprogramminglanguage,andClanguagefunctionlibraryisadocumentwritteninClanguage.ItisconvenientforlatecomerstousetheClanguagemoresimplyandquickly.

2,Clanguageisanintroductorylanguageforprogramming.SincetheClanguagestatementdoesnotprovideastatementtodirectlycalculatethesinorcosfunction,itwillcausedifficultyinwritingtheprogram;butthefunctionlibraryprovidesthesinandcosfunctions,whichcanbeusedtodirectlycall.Todisplayaparagraphoftext,wecan'tfindthedisplaystatementinClanguage,wecanonlyusethelibraryfunctionprintf.ThelibraryfunctionofClanguageisnotapartofClanguageitself,itisasetofprogramscompiledandprovidedbythecompileraccordingtotheneedsofgeneralusers.TheClibraryfunctionsgreatlyfacilitateusers,andatthesametimesupplementthedeficienciesoftheClanguageitself.WhenwritingaClanguageprogram,usinglibraryfunctionscannotonlyimprovetheoperatingefficiencyoftheprogram,butalsoimprovethequalityofprogramming.

Related Articles
TOP