c语言的用法.docx
《c语言的用法.docx》由会员分享,可在线阅读,更多相关《c语言的用法.docx(20页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、c语言的用法c语言的用法语言程序设计是一门基础的程序设计语言,学好这门课对以后程序开发至关重要。由于C语言灵敏、强大,初学者要全面地把握它非常吃力,因而在学习C语言的经过中,但一定要熟练把握C语言的流程控制语句、数组、函数、指针等基础知识的应用,为学习面向对象程序设计打下坚实的基础。下面我就为大家来介绍下c语言的用法。c语言的用法:abort功能:异常终止一个进程用法:voidabort(void);程序例:#includestdio.h#includestdlib.hintmain(void)printf(Callingabort()nabort();return0;/*Thisisneve
2、rreached*/c语言的用法:abs功能:求整数的绝对值用法:intabs(inti);程序例:#includestdio.h#includemath.hintmain(void)intnumber=-1234;printf(number:%dabsolutevalue:%dn,number,abs(number);return0;c语言的用法:absread,abswirte功能:绝对磁盘扇区读、写数据用法:intabsread(intdrive,intnsects,intsectno,void*buffer);intabswrite(intdrive,intnsects,intsect
3、no,void*buffer);程序例:/*absreadexample*/#includestdio.h#includeconio.h#includeprocess.h#includedos.hintmain(void)inti,strt,ch_out,sector;charbuf512;printf(InsertadisketteintodriveAandpressanykeyngetch();sector=0;if(absread(0,1,sector,buf)!=0)perror(Diskproblemexit(1);printf(ReadOKnstrt=3;for(i=0;ii+)c
4、h_out=bufstrt+i;putchar(ch_out);printf(nreturn(0);c语言的用法:access功能:确定文件的访问权限用法:intaccess(constchar*filename,intamode);程序例:#includestdio.h#includeio.hintfile_exists(char*filename);intmain(void)printf(DoesNOTEXIST.FILexist:%sn,file_exists(NOTEXISTS.FIL)?YES:NOreturn0;intfile_exists(char*filename)return
5、(access(filename,0)=0);c语言的用法:acos功能:反余弦c语言的用法用法:doubleacos(doublex);程序例:#includestdio.h#includemath.hintmain(void)doubleresult;doublex=0.5;result=acos(x);printf(Thearccosineof%lfis%lfn,x,result);return0;c语言的用法:allocmem功能:分配DOS存储段用法:intallocmem(unsignedsize,unsigned*seg);程序例:#includedos.h#includeall
6、oc.h#includestdio.hintmain(void)unsignedintsize,segp;intstat;size=64;/*(64x16)=1024bytes*/stat=allocmem(size,segp);if(stat=-1)printf(Allocatedmemoryatsegment:%xn,segp);elseprintf(Failed:maximumnumberofparagraphsavailableis%un,stat);return0;c语言的用法:arc功能:画一弧线用法:voidfararc(intx,inty,intstangle,intendan
7、gle,intradius);程序例:#includegraphics.h#includestdlib.h#includestdio.h#includeconio.hintmain(void)/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy;intstangle=45,endangle=135;intradius=100;/*initializegraphicsandlocalvariables*/initgraph(gdriver,gmode,/*readresultofinitialization*
8、/errorcode=graphresult();/*anerroroccurred*/if(errorcode!=grOk)printf(Graphicserror:%sn,grapherrormsg(errorcode);printf(Pressanykeytohalt:getch();exit(1);/*terminatewithanerrorcode*/midx=getmaxx()/2;midy=getmaxy()/2;setcolor(getmaxcolor();/*drawarc*/arc(midx,midy,stangle,endangle,radius);/*cleanup*/
9、getch();closegraph();return0;c语言的用法:asctime功能:转换日期和时间为ASCII码用法:char*asctime(conststructtm*tblock);程序例:#includestdio.h#includestring.h#includetime.hintmain(void)structtmt;charstr80;/*sampleloadingoftmstructure*/t.tm_sec=1;/*Seconds*/t.tm_min=30;/*Minutes*/t.tm_hour=9;/*Hour*/t.tm_mday=22;/*DayoftheMo
10、nth*/t.tm_mon=11;/*Month*/t.tm_year=56;/*Year-doesnotincludecentury*/t.tm_wday=4;/*Dayoftheweek*/t.tm_yday=0;/*Doesnotshowinasctime*/t.tm_isdst=0;/*IsDaylightSavTime;doesnotshowinasctime*/*convertsstructuretonullterminatedstring*/strcpy(str,asctime(t);printf(%sn,str);return0;c语言的用法:asin功能:反正弦c语言的用法用
11、法:doubleasin(doublex);程序例:#includestdio.h#includemath.hintmain(void)doubleresult;doublex=0.5;result=asin(x);printf(Thearcsinof%lfis%lfn,x,result);return(0);c语言的用法:assert功能:测试一个条件并可能使程序终止用法:voidassert(inttest);程序例:#includeassert.h#includestdio.h#includestdlib.hstructITEMintkey;intvalue;/*additemtolis
12、t,makesurelistisnotnull*/voidadditem(structITEM*itemptr)assert(itemptr!=NULL);/*additemtolist*/intmain(void)additem(NULL);return0;c语言的用法:atan功能:反正切c语言的用法用法:doubleatan(doublex);程序例:#includestdio.h#includemath.hintmain(void)doubleresult;doublex=0.5;result=atan(x);printf(Thearctangentof%lfis%lfn,x,resu
13、lt);return(0);c语言的用法:atan2功能:计算Y/X的反正切值用法:doubleatan2(doubley,doublex);程序例:#includestdio.h#includemath.hintmain(void)doubleresult;doublex=90.0,y=45.0;result=atan2(y,x);printf(Thearctangentratioof%lfis%lfn,(y/x),result);return0;c语言的用法:atexit功能:注册终止c语言的用法用法:intatexit(atexit_tfunc);程序例:#includestdio.h#
14、includestdlib.hvoidexit_fn1(void)printf(Exitfunction#1callednvoidexit_fn2(void)printf(Exitfunction#2callednintmain(void)/*postexitfunction#1*/atexit(exit_fn1);/*postexitfunction#2*/atexit(exit_fn2);return0;c语言的用法:atof功能:把字符串转换成浮点数用法:doubleatof(constchar*nptr);程序例:#includestdlib.h#includestdio.hintma
15、in(void)floatf;char*str=12345.67f=atof(str);printf(string=%sfloat=%fn,str,f);return0;c语言的用法:atoi功能:把字符串转换成长整型数用法:intatoi(constchar*nptr);程序例:#includestdlib.h#includestdio.hintmain(void)intn;char*str=12345.67n=atoi(str);printf(string=%sinteger=%dn,str,n);return0;c语言的用法:atol功能:把字符串转换成长整型数用法:longatol(c
16、onstchar*nptr);程序例:#includestdlib.h#includestdio.hintmain(void)longl;char*str=98765432l=atol(lstr);printf(string=%sinteger=%ldn,str,l);return(0);c语言的用法:bar功能:画一个二维条形图用法:voidfarbar(intleft,inttop,intright,intbottom);程序例:#includegraphics.h#includestdlib.h#includestdio.h#includeconio.hintmain(void)/*re
17、questautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy,i;/*initializegraphicsandlocalvariables*/initgraph(gdriver,gmode,/*readresultofinitialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/printf(Graphicserror:%sn,grapherrormsg(errorcode);printf(Pressanykeytohalt:g
18、etch();exit(1);/*terminatewithanerrorcode*/midx=getmaxx()/2;midy=getmaxy()/2;/*loopthroughthefillpatterns*/for(i=SOLID_FILL;iUSER_FILL;i+)/*setthefillstyle*/setfillstyle(i,getmaxcolor();/*drawthebar*/bar(midx-50,midy-50,midx+50,midy+50);getch();/*cleanup*/closegraph();return0;c语言的用法:bar3d功能:画一个三维条形图
19、用法:voidfarbar3d(intleft,inttop,intright,intbottom,intdepth,inttopflag);程序例:#includegraphics.h#includestdlib.h#includestdio.h#includeconio.hintmain(void)/*requestautodetection*/intgdriver=DETECT,gmode,errorcode;intmidx,midy,i;/*initializegraphics,localvariables*/initgraph(gdriver,gmode,/*readresultof
20、initialization*/errorcode=graphresult();if(errorcode!=grOk)/*anerroroccurred*/printf(Graphicserror:%sn,grapherrormsg(errorcode);printf(Pressanykeytohalt:getch();exit(1);/*terminatewitherrorcode*/midx=getmaxx()/2;midy=getmaxy()/2;/*loopthroughthefillpatterns*/for(i=EMPTY_FILL;iUSER_FILL;i+)/*setthefi
21、llstyle*/setfillstyle(i,getmaxcolor();/*drawthe3-dbar*/bar3d(midx-50,midy-50,midx+50,midy+50,10,1);getch();/*cleanup*/closegraph();return0;c语言的用法:bdos功能:DOS系统调用用法:intbdos(intdosfun,unsigneddosdx,unsigneddosal);程序例:#includestdio.h#includedos.h/*GetcurrentdriveasA,B,.*/charcurrent_drive(void)charcurdr
22、ive;/*Getcurrentdiskas0,1,.*/curdrive=bdos(0x19,0,0);return(A+curdrive);intmain(void)printf(Thecurrentdriveis%c:n,current_drive();return0;c语言的用法:bdosptr功能:DOS系统调用用法:intbdosptr(intdosfun,void*argument,unsigneddosal);程序例:#includestring.h#includestdio.h#includedir.h#includedos.h#includeerrno.h#includes
23、tdlib.h#defineBUFLEN80intmain(void)charbufferBUFLEN;inttest;printf(Enterfullpathnameofadirectoryngets(buffer);test=bdosptr(0x3B,buffer,0);if(test)printf(DOSerrormessage:%dn,errno);/*Seeerrno.hforerrorlistings*/exit(1);getcwd(buffer,BUFLEN);printf(Thecurrentdirectoryis:%sn,buffer);return0;c语言的用法:bios
24、com功能:串行I/O通信用法:intbioscom(intcmd,charabyte,intport);程序例:#includebios.h#includeconio.h#defineCOM10#defineDATA_READY0x100#defineTRUE1#defineFALSE0#defineSETTINGS(0x80|0x02|0x00|0x00)intmain(void)intin,out,status,DONE=FALSE;bioscom(0,SETTINGS,COM1);cprintf(.BIOSCOMESCtoexit.nwhile(!DONE)status=bioscom
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 用法
限制150内