![單片機(jī)學(xué)習(xí)庫函數(shù)詳解_第1頁](http://file4.renrendoc.com/view12/M0B/1C/1D/wKhkGWX_RPCAeCJ2AAFDYwTTTQc205.jpg)
![單片機(jī)學(xué)習(xí)庫函數(shù)詳解_第2頁](http://file4.renrendoc.com/view12/M0B/1C/1D/wKhkGWX_RPCAeCJ2AAFDYwTTTQc2052.jpg)
![單片機(jī)學(xué)習(xí)庫函數(shù)詳解_第3頁](http://file4.renrendoc.com/view12/M0B/1C/1D/wKhkGWX_RPCAeCJ2AAFDYwTTTQc2053.jpg)
![單片機(jī)學(xué)習(xí)庫函數(shù)詳解_第4頁](http://file4.renrendoc.com/view12/M0B/1C/1D/wKhkGWX_RPCAeCJ2AAFDYwTTTQc2054.jpg)
![單片機(jī)學(xué)習(xí)庫函數(shù)詳解_第5頁](http://file4.renrendoc.com/view12/M0B/1C/1D/wKhkGWX_RPCAeCJ2AAFDYwTTTQc2055.jpg)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
PICC庫函PICCPICC庫函PICC編譯器的庫函數(shù)。每個函數(shù)均從函數(shù)名開始,然后按照以下提要C語言定義以及定義函數(shù)的頭文件。描述對函數(shù)及其目的進(jìn)行敘述性描述。例程:給出一個能說明該函數(shù)的應(yīng)用例子。參閱:給出相關(guān)聯(lián)的函數(shù)。返回值:如果函數(shù)有返回值,則在本標(biāo)題下將給出返回值的類型和性質(zhì),同時還包括 ABS函數(shù)#includeintabs(intabs函數(shù)返回變量j的絕對值3.程#include<stdio.h>#include<stdlib.h>main{inta=-printf("Theabsolutevalueof%dis}4.返回值j ACOS#includedoubleacos(doubleacos()函數(shù)是cos()的反函數(shù)。函數(shù)參數(shù)在[-1,1]區(qū)間內(nèi),返回值是一個用弧度表3.例程1#include<math.h>#include#include<math.h>#includemain{floatfor(i=-1.0,i<1.0;i+={a=acos(i)*180.0/3.141592;printf("acos(%f)=%fdegrees\n",i,a);}}4.閱sin(),cos(),tan(),asin(),atan(),atan2(5.返回值 ASCTIME函#includechar*asctime(structtm*asctimet從上structtm結(jié)構(gòu)體中獲得時間,返回描述當(dāng)前日期和時SunSep1601:03:52當(dāng)前時間,通過localtime函數(shù)將其轉(zhuǎn)換成一個structtm指針,最后轉(zhuǎn)換成ASCII印出來。其中,time()函數(shù)需要用戶提供(詳情請參閱time()函數(shù)3.例程#include<stdio.h>#include<time.h>main{time_tclock;structtm*tp;tp=2}4.參閱}4.參閱ctime(),gmtime(),localtime(),time(返回值注意:由于編譯器不提供time()例行程序,故在本例程中它需要由用戶提供。詳情請參照time函數(shù)據(jù)類structtminttm_sec;inttm_min;inttm_hour;inttm_mday;inttm_mon;inttm_year;inttm_wday;inttm_yday;inttm_isdst;4ASIN#includedoubleasin(doubleasin(函數(shù)是sin(的反函數(shù)。它的函數(shù)參數(shù)在[-1,1]3.例程#include<math.h>#include<stdio.h>main{floatfor(i=-1.0;i<1.0;i+={a=asin(i)*180.0/3.141592;printf("asin(%f)=%fdegrees\n",i,a);}}34.參閱sin(),cos(),tan(),acos(),atan(),4.參閱sin(),cos(),tan(),acos(),atan(),atan2(5.返回值5ATAN#includedoubleatan(double而且有tan(e)=x(x為函數(shù)參數(shù)3.程#include<stdio.h>#include<math.h>main{}4.閱sin(),cos(),tan(),asin(),acos(),atan2(返回值5. ATAN2#includedoubleatan2(doubley,double本函數(shù)返回y/x3.程#include<stdio.h>#include<math.h>main{}4.閱4sin(),cos(),tan(),asin(),acos(sin(),cos(),tan(),asin(),acos(),atan(5.返回值 ATOF#includedoubleatof(constchar*3.程#include<stdlib.h>#include<stdio.h>main{charbuf[80];doublei;i=printf("Read%s:convertedto}4.閱atoi(),atol(5.返回值本函數(shù)返回一個雙精度浮點(diǎn)數(shù)。如果字符串中沒有發(fā)現(xiàn)任何數(shù)字,則返回0.08ATOI#includeintatoi(constchar*atoi()函數(shù)掃描傳遞過來的字符串,跳過開頭的空格并讀取其符號;制數(shù)的ASCII表達(dá)式轉(zhuǎn)換成整數(shù)3.例程#include<stdlib.h>#include5main{charbuf[80];inti;i=printf("Read%s:main{charbuf[80];inti;i=printf("Read%s:convertedto}4.參閱xtoi(),atof(),atol(5.返回值9ATOL#includelongatol(constchar*atol函數(shù)掃描傳遞過來的字符串,并跳過字符串開頭的空格;然后將十進(jìn)制數(shù)的3.例程#include<stdlib.h>#include<stdio.h>main{charbuf[80];longi;i=printf("Read%s:convertedto}參閱4.atoi(),atof(返回值5.CEIL#include6doubleceil(double本函數(shù)對函數(shù)參數(shù)ff例程#include<stdio.h>#include<math.h>doubleceil(double本函數(shù)對函數(shù)參數(shù)ff例程#include<stdio.h>#include<math.h>main{doublej;scanf("%lf",printf("Theceilingof%lfis} COS#includedoublecos(double3.程#include<math.h>#include<stdio.h>#defineC3.141592/180.0main{doublefor(i=0;i<=180.0;i+=printf("sin(%3.0f)=%f,cos=}4.閱sin(),tan(),asin(),acos(),atan(),atan2(5.返回值返回一個雙精度數(shù),區(qū)間為[-1,1]COSHSINHTANH#includedoublecosh(double7doublesinh(doubledoubletanh(double這些函數(shù)都是cos(),doublesinh(doubledoubletanh(double這些函數(shù)都是cos(),sin()和tan()3.例程#include<stdio.h>#include<math.h>main{printf("%f\n",cosh(1.5));printf("%f\n",sinh(1.5));}4.返回值cosh()函數(shù)返回雙曲余弦值,sinh()函數(shù)返回雙曲正弦值,tanh()函數(shù)返回雙曲正切CTIME#includechar*ctime(time_t*ctime()函數(shù)將函數(shù)參數(shù)所指的時間轉(zhuǎn)換成字符串,其結(jié)構(gòu)與asctime()3.程#include<stdio.h>#include<time.h>main{time_tclock;}4.閱gmtime(),localtime(),asctime(),time(5.返回值()()6.數(shù)據(jù)類8typedeflongDIEI#include<pic.h>voidei(void)voidtypedeflongDIEI#include<pic.h>voidei(void)void()()的連續(xù)字期間出現(xiàn)中斷,則函數(shù)getticks()將返回錯誤的值。3.程#include<pic.h>longcount;voidinterrupt{}long{longval/*在訪問count變量前禁止中斷,保證訪問的連續(xù)性*/di();val=count;ei();returnval;}DIV#includediv_tdiv(intnumer,intdiv(3.程#include<stdlib.h>#include<stdio.h>main{9div_tx=printf("quotientdiv_tx=printf("quotient=%d,remainder=}返回值返回一個包括商和余數(shù)的結(jié)構(gòu)體div_t。4.5.數(shù)據(jù)typedef{intquot;int}EEPROM_READ、EEPROM_WRITE函#includeunsignedchareeprom_read(unsignedcharvoideeprom_write(unsignedcharaddr,unsignedcharEEPO3.例程#include<pic.h>main{unsignedchardata;address=0x10;data=}注意:如果調(diào)用eeprom_write()函數(shù)后需即刻調(diào)用eeprom_read()函數(shù),則必須查詢EEPROM寄存以確保寫入完畢。全局中斷使能位(GIE)在eeprom_write(程序中重新恢復(fù)(寫EEPROM時需要關(guān)閉EVAL_POLY函#includedoubleeval_poly(doublex,constdouble*#includedoubleeval_poly(doublex,constdouble*d,inty=x*x*d2+x*d1+3.程#include<stdio.h>#include<math.h>main{doubledoubled[3]={1.1,3.5,2.7};x=2.2;y=printf("Thepolynomialevaluatedat%fis}4.返回值EXP#includedoubleexp(doubleexp()函數(shù)返回參數(shù)的指數(shù)函數(shù)值,即ef(f為函數(shù)參數(shù)3.程#include<math.h>#include<stdio.h>main{doublefor(f=0.0;f<=5;f+=printf("eto%1.0f=}4.閱log(),log10(),pow(FABS#includedoublefabs(double3.程#include<stdio.h>#includeFABS#includedoublefabs(double3.程#include<stdio.h>#include<math.h>main{printf("%f%f\n",fabs(1.5),fabs(-}4.閱abs(FLOOR函#includedoublefloor(double本函數(shù)對函數(shù)參數(shù)取整,取整后的返回值不大于函數(shù)參數(shù)f3.程#include<stdio.h>#include<math.h>main{printf("%f\n",floor(1.5));printf("%f\n",floor(-}FREXP函#includedoublefrexp(doublef,int*frexp()函數(shù)將一個浮點(diǎn)數(shù)分解成規(guī)格化小數(shù)和2的整數(shù)次冪兩部分,整數(shù)冪部分存于指針p所指的int單元中。本函數(shù)的返回值x或在區(qū)間(0.5,1.0)內(nèi),或?yàn)?;而且有f=x×2p。如果f為0,則分解出來的兩部分均為0。3.程#include<math.h>#include<stdio.h>main{doublef3.程#include<math.h>#include<stdio.h>main{doublef;inti;f=frexp(23456.34,&i);printf("23456.34=%f*2^%d\n",f,i);}4.閱ldexp(GET_CAL_DATA函#includedoubleget_cal_data(constunsignedchar*本函數(shù)從PIC14000標(biāo)定空間返回一個32位的浮點(diǎn)標(biāo)定數(shù)據(jù)。只有利用這個函數(shù)才3.程#include<pic.h>main{doublex;x=get_cal_data(KREF);/*獲得參考斜率(slopereferenceratio)*/y=TWDT;/*獲得WDT溢出時間*/}4.返回值注意:本函數(shù)僅用于PICGMTIME函#includestructtm*gmtime(time_t*t所指的時間分解,并且存于結(jié)構(gòu)體中,精確度為秒。其中,tt所指的時間分解,并且存于結(jié)構(gòu)體中,精確度為秒。其中,t3.程#include<stdio.h>#include<time.h>main{time_tclock;structtm*tp;tp=printf("It’s%dinLondon\n",tp-}4.閱ctime(),asctime(),time(),localtime(返回值返回tm()()5.6.數(shù)據(jù)typedeflongtime_t;structtm{inttm_sec;inttm_min;inttm_hour;inttm_mday;inttm_mon;inttm_year;inttm_wday;inttm_yday;inttm_isdst;等函數(shù)#include<ctype.h>intisalnum(charc)intisalpha(charc)intisascii(charc)intiscntrl(charintisdigit(charc)intislower(charc)intisprint(charc)intisgraph(charintisdigit(charc)intislower(charc)intisprint(charc)intisgraph(charc)intispunct(charc)intisspace(charintisupper(charc)intisxdigit(charisalpha(c)isascii(c)iscntrl(c)isdigit(c)islowerc)isprint(c)isgraphc)ispunct(c)isspace(c)isupperc)isxdigitc)例程#include#include<stdio.h>main{charbuf[80];inti;i=c是空格鍵、TAB鍵或換行符c在A~Z范圍內(nèi)c在0~9、a~f或A~F范圍內(nèi)buf[i]=printf("’%s’isthe}參toupper(),tolower(),toascii(KBHIT函#includebitkbhit如果鍵盤上的字符被按下,函數(shù)返回1;否則返回0。通常,該字符可通過getch()KBHIT函#includebitkbhit如果鍵盤上的字符被按下,函數(shù)返回1;否則返回0。通常,該字符可通過getch()3.程#include<conio.h>main{inti;while(!kbhit()){cputs("I’mwaiting..");for(i=0;i!=1000;}}4.閱getch(),getche(返回值注意:程序的主體需由用戶實(shí)現(xiàn),其主要框架可以從sources目錄下直接獲得5.LDEXP#includedoubleldexp(doublef,intldexp(函數(shù)是frexp(i3.例程#include<math.h>#include<stdio.h>main{doublef=printf("1.0*2^10=}4.參閱frexp(5.返回值本函數(shù)返回浮點(diǎn)數(shù)fiLDIV#include}4.參閱frexp(5.返回值本函數(shù)返回浮點(diǎn)數(shù)fiLDIV#includeldiv_tldiv(longnumber,long3.例程#include<stdlib.h>#include<stdio.h>main{ldiv_tlt=printf("Quotient=%ld,remainder=}4.參閱div(返回值返回值是結(jié)構(gòu)體ldiv_t數(shù)據(jù)結(jié)typedef{longquot;/*longrem;/*余數(shù)5.6.LOCALTIME函#includestructtm*localtime(time_t*需要考慮全局整型變量time_zone中的內(nèi)容,因?yàn)樗斜镜貢r區(qū)位于格林威治以西的函數(shù)的返回值將與gmtime()的相同。3.例#include#include<time.h>char*wday[]={main{time_tclock;structtm*tp;tp=printf("Todayis%s\n",wday[tp-}4.閱ctime(),asctime(),time(返回值本函數(shù)返回tm()()5.6.數(shù)據(jù)typedeflongtime_t;structtm{inttm_sec;inttm_min;inttm_hour;inttm_mday;inttm_mon;inttm_year;inttm_wday;inttm_yday;inttm_isdst;LOGLOG10#includedoublelog(doublef)doublelog10(doublef)log(函數(shù)返回f的自然對數(shù)值。log10(函數(shù)返回f#includedoublelog(doublef)doublelog10(doublef)log(函數(shù)返回f的自然對數(shù)值。log10(函數(shù)返回f以103.程#include<math.h>#include<stdio.h>main{doublefor(f=1.0;f<=10.0;f+=1.0)printf("log(%1.0f)=%f\n",f,log(f));}4.閱exp(),pow(返回值5.MEMCHR函#include/*初級和中級系列單片機(jī)constvoid*memchr(constvoid*block,intval,size_t/*高級系列單片機(jī)void*memchr(constvoid*block,intval,size_tmemchr函數(shù)與strchr函數(shù)在功能上類似;但前者沒有在字符串中尋找null(空)中止字符的功能。memchr函數(shù)實(shí)現(xiàn)在一段規(guī)定了長度的內(nèi)存區(qū)域中尋找特定的字節(jié)。它3.例程#include<string.h>#include<stdio.h>unsignedintary[]={1,5,0x6789,0x23};main{char*cp=memchr(ary,0x89,sizeofprintf("notfound\n");printf("Foundatoffset%u\n"printf("notfound\n");printf("Foundatoffset%u\n",cp-(char}4.參閱strchr(5.返回值NULLMEMCMP函#includeintmemcmp(constvoid*s1,constvoid*s2,size_tmemcmp()函數(shù)的功能是比較兩塊長度為n的內(nèi)存中變量的大小,類似strncmp函碼字符順序被用來比較;但如果內(nèi)存塊中包含非ASCII碼字符,則返回值不確定。測試3.程#include<stdio.h>#include<string.h>main{intbuf[10],cow[10],i;buf[0]=1;buf[2]=cow[0]=cow[2]=buf[1]=cow[1]=i=memcmp(buf,cow,3*sizeof(int));if(i<0)printf("lessthan\n");elseif(i>0)printf("Greaterthan\n");}4.參閱strncpy(),strncmp(),strchr(),memset(),4.參閱strncpy(),strncmp(),strchr(),memset(),5.返回值s1s2變量時,函數(shù)返回值分別為-1,0或1。MEMCPY函#include/*低級或中級系列單片機(jī)void*memcpy(void*d,constvoid*s,size_t/*高級系列單片機(jī)farvoid*memcpy(farvoid*d,constvoid*s,size_t,3.程#include<string.h>#include<stdio.h>main{charmemset(buf,0,sizeofbuf);memcpy(buf,"apartialstring",10);printf("buf=’%s’\n",buf);}4.閱strncpy(),strncmp(),strchr(),5.返回值memcpy() MEMMOVE函#include/*低級或中級系列單片機(jī)void*memmove(void*s1,constvoid*s2,size_t/*高級系列單片機(jī)farvoid*memmove(farvoid*s1,constvoid*s2,size_tmemmove()函數(shù)與memcpy()函數(shù)相似,但memmove()3.參閱strncpy(),strncmp(),strchr(),返回值memmove()4.MEMSET函memmove()函數(shù)與memcpy()函數(shù)相似,但memmove()3.參閱strncpy(),strncmp(),strchr(),返回值memmove()4.MEMSET函#include/*低級和中級系列的單片機(jī)*/void*memset(void*s,intc,size_tn)/*高級系列單片機(jī)farvoid*memset(farvoid*s,intc,size_tmemset()函數(shù)將字節(jié)c存儲到指針s指向的,內(nèi)存開始的n個內(nèi)存字節(jié)3.例程#include<string.h>#include<stdio.h>main{charstrcpy(abuf,"Thisisastring");memset(abuf,’x’,5);printf("buf=’%s’\n",}4.參閱strncpy(),strncmp(),strchr(),memcpy(),MODF#includedoublemodf(doublevalue,double*173.例程#include#includemain{doublei_val,main{doublei_val,f_val=modf(-3.17,}4.返回值PERSIST_CHECK,PERSIST_VALIDATE函數(shù)#includeintpersist_check(intflag)voidpersist_validate(void)persist_check()函數(shù)要用到非可變(non-volatile)的RAM變量,這些變量在定義時被數(shù),并用到一個存儲在隱藏變量中的虛擬數(shù)據(jù),且由persist_validate()函數(shù)計(jì)算得到一個3.程#include<sys.h>#include<stdio.h>main{printf("Resetcountinvalid-zeroed\n");printf("Resetnumber%ld\n",reset_count);reset_count++;/*updatecount*/persist_validate();/*andchecksum*/continue;/*sleepuntilnextreset}4.返回值,,(非零POW#includedoublepow(doublef,doublepow()POW#includedoublepow(doublef,doublepow()函數(shù)表示第一個參數(shù)f的p次冪3.程#include<math.h>#include<stdio.h>main{doublefor(f=1.0;f<=10.0;f+=printf("pow(2,%1.0f)=%f\n",f,pow(2,}4.閱log(),log10(),返回值返回值為f的p5.PRINTF函#includeunsignedcharprintf(constchar*fmt,(tout轉(zhuǎn)換格式的形式為%m.nc。其中%表示格式,m表示選擇的字符寬度,n表示選擇的如果指針變量為十進(jìn)制常數(shù),例如格式為%*doxXuS打印一個字符串——函數(shù)參數(shù)值被認(rèn)為是字符型指針。最多從字符串中取n符打印,字符寬度為m符打印,字符寬度為m 3.例程printf("Total=%4d%%",23)輸出為’Total=23%’printf("Sizeis%lx",size)這里size為長整型十六進(jìn)制變量。注意當(dāng)使用%s時,精度只對中級和高級printf("Name=%.8s",輸出為’Name=printf("xx%*d",3,輸出為’xx/*vprintf例程*/#include<stdio.h>error(char*s,{va_listap;va_start(ap,s);printf("Error:");vprintf(s,ap);}main{inti;i=error("testing12%d",}參見sprintf()函數(shù)4.返回值printf()將返回的字符值寫到標(biāo)準(zhǔn)輸出口。注意返回值為字符型,而不是整形關(guān)PICC–L的描述以及有關(guān)HPDPIC長整型關(guān)PICC–L的描述以及有關(guān)HPDPIC長整型格式在printf的菜單選項(xiàng)RAND#includeintrand每次被調(diào)用后,以隨機(jī)數(shù)據(jù)形式出現(xiàn)。這一運(yùn)算規(guī)則將產(chǎn)生一個從同一起點(diǎn)開始的確定3.例程#include<stdlib.h>#include<stdio.h>#include<time.h>main{time_ttoc;inti;for(i=0;i!=10;i++)printf("%d\t",rand());}參見srand()函數(shù)()SIN#includedoublesin(double3.例#include<math.h>#include<stdio.h>#defineC3.141592/180.0main{doublefor(i=0;main{doublefor(i=0;i<=180.0;i+=printf("sin(%3.0f)=%f,cos=%f\n",i,sin(i*C),}4.參閱cos(),tan(),asin(),acos(),atan(),5.返回值返回值為參數(shù)f SPRINTF函#include/*中級和低級系列單片機(jī)unsignedcharsprintf(char*buf,constchar*fmt,/*高級系列單片機(jī)unsignedcharsprintf(farchar*buf,constchar*fmt,sprintf()函數(shù)printf()函數(shù)操作基本相同只是輸出在不同的輸出終端,所有的字符被放到buf緩沖器。字符串帶有空格結(jié)束符,buf緩沖器中的數(shù)據(jù)被返回。printf()3.返回值sprintf()函數(shù)的返回值為被放入緩沖器中的數(shù)據(jù)。注意,返回值為字符型而非整型SQRT#includedoublesqrt(doublesqrt()函數(shù)利用牛頓法得到參數(shù)的近似平方根3.程#include<math.h>#include<stdio.h>main{doublefor(i=0;i<=20.0;i+=printf("squarerootof%.1f=%f\n",i,}4.返回值SRAND函#includevoid4.返回值SRAND函#includevoidsrand(unsignedintsrand()函數(shù)是在調(diào)用rand()函數(shù)時被用來初始化隨機(jī)數(shù)據(jù)發(fā)生器的。它為rand()函3.例程#include<stdlib.h>#include<stdio.h>#include<time.h>main{time_ttoc;inti;for(i=0;i!=10;i++)printf("%d\t",rand());}rand()STRCAT函#include/*char*strcat(char*s1,constchar*/*高級系列單片機(jī)farchar*strcat(farchar*s1,constchar*s2s1的后面。新的字符串以空格作為結(jié)束符。指針型參數(shù)s1指向的字符數(shù)組必須保證大于結(jié)果字符串。3.例程#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofs1=s2="...endofline";strcat(s1,s2);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}4.閱strcpy(),strcmp(),strncat(),返回值5.STRCHR,STRICHR函數(shù)#include/*中級和低級系列單片機(jī)constchar*strchr(constchar*s,intc)constchar*strichr(constchar*s,intc)/*高級系列單片機(jī)char*strchr(constchar*s,intchar*strichr(constchar*s,intstrchr()sc。如果找到了,則字符指針被返回0。Strichr()strchr()3.例程#include<stdio.h>main{staticchartemp[]="Hereitis...";charc=’s’;if(strchr(temp,printf("Character%cwasfoundinstring\n",printf("Nocharacterwasfoundin}4printf("Nocharacterwasfoundin}4.參閱strrchr(),strlen(),5.返回值0STRCMP,STRICMP函數(shù)#includeintstrcmp(constchar*s1,constchar*s2)intstricmp(constchar*s1,constchar*s2)strcmp()2s1表進(jìn)行的。Stricmp()函數(shù)功能和strcmp()函數(shù)完全一樣。3.例#include<string.h>#include<stdio.h>main{intif((i=strcmp("ABC","ABc"))<0)printf("ABCislessthanABc\n");elseif(i>0)printf("ABCisgreaterthanprintf("ABCisequalto}4.參閱strlen(),strncmp(),strcpy(),5.返回值-11STRCPY函#include/*低級和中級系列單片機(jī)char*strcpy(char*#include/*低級和中級系列單片機(jī)char*strcpy(char*s1,constchar*/*高級系列單片機(jī)farchar*strcpy(farchar*s1,constchar*s2s1s23.程#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofline");s1=buffer;s2="...endofline";strcat(s1,s2);printf("Length=%d\n",printf("string=\"%s\"\n",}4.閱strncpy(),strlen(),strcat(),5.返回值STRCSPN函#includesize_tstrcspn(constchar*s1,constchar*strcspn()函數(shù)用于取得在字符串常數(shù)s1中有而字符串常s23.程#include<stdio.h>#include<string.h>main{staticcharset[]=printf("%d\n",strcspn("abcdevwxyz",set));printf("%d\n",strcspn("xxxbcadefs",set));printf("%d\n",strcspn("1234567890",set));}參見strspn()函數(shù)4.返回值printf("%d\n",strcspn("abcdevwxyz",set));printf("%d\n",strcspn("xxxbcadefs",set));printf("%d\n",strcspn("1234567890",set));}參見strspn()函數(shù)4.返回值STRLEN函#includesize_tstrlen(constchar*strlen()s13.例程#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofline");s1=buffer;s2="...endofline";strcat(s1,s2);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}4.返回值 STRNCAT函#include/*低級和中級系列單片機(jī)char*strncat(char*s1,constchar*s2,size_t/*高級系列單片機(jī)farchar*strncat(farchar*s1,constchar*s2,size_ts2s1ns1指向的字符數(shù)組應(yīng)足夠大,3.程#include<string.h>#include<stdio.h>mains1指向的字符數(shù)組應(yīng)足夠大,3.程#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strcpy(buffer,"Startofline");s1=buffer;s2="...endofline";strncat(s1,s2,5);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}4.閱strcpy(),strcmp(),strcat(),返回值5.STRNICMP函數(shù)#includeintstrncmp(constchar*s1,constchar*s2,size_tn)intstrnicmp(constchar*s1,constchar*s2,size_tn)據(jù)字符串s1是否小于、等于或大于字符串s2,返回一個有符號數(shù)。比較是根據(jù)ASCII字順序進(jìn)行的。Strnicmp()函數(shù)與之相同3.例程#include<stdio.h>#include<string.h>main{inti=strcmp("abcxyz","abcxyz");if(i==0)printf("Bothstringsareelseif(i>printf("String2lessthanstring1\n");printf("String2iselseif(i>printf("String2lessthanstring1\n");printf("String2isgreaterthanstring}4.參閱strlen(),strcmp(),strcpy(),5.返回值 STRNCPY函#include/*低級和中級系列單片機(jī)char*strncpy(char*s1,constchar*s2,size_t/*高級系列單片機(jī)farchar*strncpy(farchar*s1,constchar*s2,size_t這個函數(shù)將帶結(jié)束符的字符串s2拷貝到字符指針s1指向的字符數(shù)組。最多有n個字3.程#include<string.h>#include<stdio.h>main{charbuffer[256];char*s1,*s2;strncpy(buffer,"Startofline",6);s1=buffer;s2="...endofline";strcat(s1,s2);printf("Length=%d\n",strlen(buffer));printf("string=\"%s\"\n",buffer);}4.閱strcpy(),strcat(),strlen(),5.返回值指針s1指向的目的緩沖區(qū) STRPBRK函#include/*低級和中級系列單片機(jī)constchar STRPBRK函#include/*低級和中級系列單片機(jī)constchar*strpbrk(constchar*s1,constchar*/*高級系列單片機(jī)char*strpbrk(constchar*s1,constchar*s23.程#include<stdio.h>#include<string.h>main{char*str="Thisisastring.";while(str!=NULL){printf("%s\n",strstr=strpbrk(str+1,"aeiou"}}返回值4.STRRCHR,STRRICHR函數(shù)#include/*中級和低級系列單片機(jī)*/constchar*strrchr(char*s,intc)constchar*strrichr(char*s,intc)/*高級系列單片機(jī)char*strrchr(char*s,intc)char*strrichr(char*s,intc)數(shù)和strrchr()函數(shù)完全一樣。3.例程#include#includemain{char*str="Thisisastring.";while(str!=NULL){printf("%s\n",main{char*str="Thisisastring.";while(str!=NULL){printf("%s\n",strstr=strrchr(str+1,}}4.閱strchr(),strlen(),strcmp(),strcpy(),返回值5.STRSPN函#includesize_tstrspn(constchar*s1,constchar*strspn()函數(shù)返回字符串s1中包含的、完全由字符串s2組成的字符的長度3.程#include<stdio.h>#include<string.h>main{printf("%d\n",strspn("Thisisastring","This"));printf("%d\n",strspn("Thisisastring","this"));}參見strcspn()函數(shù)4.返回值 STRSTR,STRISTR函數(shù)#include/*中級和低級系列單片機(jī)constchar*strstr(constchar*s1,constchar*s2)constchar*stristr(constchar*s1,constchar*s2)/*高級系列單片機(jī)char*strstr(con
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年自動平滑門項(xiàng)目可行性研究報(bào)告
- 2025年竹纖維家居服項(xiàng)目可行性研究報(bào)告
- 2025至2031年中國電池專用材料行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025年水管手推車項(xiàng)目可行性研究報(bào)告
- 2025年顯微(細(xì)胞)電泳系統(tǒng)項(xiàng)目可行性研究報(bào)告
- 2025至2031年中國尋像器行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025至2031年中國商業(yè)印刷票據(jù)表格行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025至2031年中國兒童多用臺行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025年免維護(hù)閥控式鉛酸電池項(xiàng)目可行性研究報(bào)告
- 2025年U型收音機(jī)項(xiàng)目可行性研究報(bào)告
- NB-T 47013.1-2015 承壓設(shè)備無損檢測 第1部分-通用要求
- 初中歷史 教材分析與教學(xué)策略 課件
- (完整word版)手卡模板
- GB/T 13912-2020金屬覆蓋層鋼鐵制件熱浸鍍鋅層技術(shù)要求及試驗(yàn)方法
- 統(tǒng)編教學(xué)小學(xué)語文課外閱讀《細(xì)菌世界歷險(xiǎn)記》導(dǎo)讀課課件
- 幼兒剪紙-打印版
- 中小學(xué)2021年秋季開學(xué)第一課手心班會圖文精品
- 高三英語閱讀專項(xiàng)訓(xùn)練之說明文(含答案及部分解析)
- 中國移動CHBN試題題庫大全(含答案)
- 醫(yī)學(xué)課件:介入放射學(xué)(全套課件328張)
- 2022年同等學(xué)力人員申請碩士學(xué)位日語水平統(tǒng)一考試真題
評論
0/150
提交評論