C语言函数大全S.docx
- 文档编号:28472168
- 上传时间:2023-07-14
- 格式:DOCX
- 页数:71
- 大小:32.55KB
C语言函数大全S.docx
《C语言函数大全S.docx》由会员分享,可在线阅读,更多相关《C语言函数大全S.docx(71页珍藏版)》请在冰豆网上搜索。
C语言函数大全S
函数名:
sbrk
功 能:
改变数据段空间位置
用 法:
char*sbrk(intincr);
程序例:
#include
#include
intmain(void)
{
printf("Changingallocationwithsbrk()\n");
printf("Beforesbrk()call:
%lubytesfree\n",
(unsignedlong)coreleft());
sbrk(1000);
printf("Aftersbrk()call:
%lubytesfree\n",
(unsignedlong)coreleft());
return0;
}
函数名:
scanf
功 能:
执行格式化输入
用 法:
intscanf(char*format[,argument,...]);
程序例:
#include
#include
intmain(void)
{
charlabel[20];
charname[20];
intentries=0;
intloop,age;
doublesalary;
structEntry_struct
{
char name[20];
int age;
floatsalary;
}entry[20];
/*Inputalabelasastringofcharactersrestrictingto20characters*/
printf("\n\nPleaseenteralabelforthechart:
");
scanf("%20s",label);
fflush(stdin); /*flushtheinputstreamincaseofbadinput*/
/*Inputnumberofentriesasaninteger*/
printf("Howmanyentrieswilltherebe?
(lessthan20)");
scanf("%d",&entries);
fflush(stdin); /*flushtheinputstreamincaseofbadinput*/
/*inputanamerestrictinginputtoonlylettersupperorlowercase*/
for(loop=0;loop { printf("Entry%d\n",loop); printf(" Name : "); scanf("%[A-Za-z]",entry[loop].name); fflush(stdin); /*flushtheinputstreamincaseofbadinput*/ /*inputanageasaninteger*/ printf(" Age : "); scanf("%d",&entry[loop].age); fflush(stdin); /*flushtheinputstreamincaseofbadinput*/ /*inputasalaryasafloat*/ printf(" Salary: "); scanf("%f",&entry[loop].salary); fflush(stdin);/*flushtheinputstreamincaseofbadinput*/ } /*Inputaname,ageandsalaryasastring,integer,anddouble*/ printf("\nPleaseenteryourname,ageandsalary\n"); scanf("%20s%d%lf",name,&age,&salary); /*Printoutthedatathatwasinput*/ printf("\n\nTable%s\n",label); printf("Compiledby%s age%d $%15.2lf\n",name,age,salary); printf("-----------------------------------------------------\n"); for(loop=0;loop printf("%4d|%-20s|%5d|%15.2lf\n", loop+1, entry[loop].name, entry[loop].age, entry[loop].salary); printf("-----------------------------------------------------\n"); return0; } 函数名: searchpath 功 能: 搜索DOS路径 用 法: char*searchpath(char*filename); 程序例: #include #include intmain(void) { char*p; /*LooksforTLINKandreturnsapointer tothepath */ p=searchpath("TLINK.EXE"); printf("SearchforTLINK.EXE: %s\n",p); /*Looksfornon-existentfile */ p=searchpath("NOTEXIST.FIL"); printf("SearchforNOTEXIST.FIL: %s\n",p); return0; } 函数名: sector 功 能: 画并填充椭圆扇区 用 法: voidfarsector(intx,inty,intstangle,intendangle); 程序例: #include #include #include #include intmain(void) { /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; intmidx,midy,i; intstangle=45,endangle=135; intxrad=100,yrad=50; /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,""); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode! =grOk) /*anerroroccurred*/ { printf("Graphicserror: %s\n",grapherrormsg(errorcode)); printf("Pressanykeytohalt: "); getch(); exit (1);/*terminatewithanerrorcode*/ } midx=getmaxx()/2; midy=getmaxy()/2; /*loopthroughthefillpatterns*/ for(i=EMPTY_FILL;i { /*setthefillstyle*/ setfillstyle(i,getmaxcolor()); /*drawthesectorslice*/ sector(midx,midy,stangle,endangle,xrad,yrad); getch(); } /*cleanup*/ closegraph(); return0; } 函数名: segread 功 能: 读段寄存器值 用 法: voidsegread(structSREGS*segtbl); 程序例: #include #include intmain(void) { structSREGSsegs; segread(&segs); printf("Currentsegmentregistersettings\n\n"); printf("CS: %X DS: %X\n",segs.cs,segs.ds); printf("ES: %X SS: %X\n",segs.es,segs.ss); return0; } 函数名: setactivepage 功 能: 设置图形输出活动页 用 法: voidfarsetactivepage(intpagenum); 程序例: #include #include #include #include intmain(void) { /*selectadriverandmodethatsupports*/ /*multiplepages. */ intgdriver=EGA,gmode=EGAHI,errorcode; intx,y,ht; /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,""); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode! =grOk) /*anerroroccurred*/ { printf("Graphicserror: %s\n",grapherrormsg(errorcode)); printf("Pressanykeytohalt: "); getch(); exit (1);/*terminatewithanerrorcode*/ } x=getmaxx()/2; y=getmaxy()/2; ht=textheight("W"); /* selecttheoffscreenpagefordrawing*/ setactivepage (1); /*drawalineonpage#1*/ line(0,0,getmaxx(),getmaxy()); /*outputamessageonpage#1*/ settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(x,y,"Thisispage#1: "); outtextxy(x,y+ht,"Pressanykeytohalt: "); /*selectdrawingtopage#0*/ setactivepage(0); /*outputamessage onpage#0*/ outtextxy(x,y,"Thisispage#0."); outtextxy(x,y+ht,"Pressanykeytoviewpage#1: "); getch(); /*selectpage#1asthevisiblepage*/ setvisualpage (1); /*cleanup*/ getch(); closegraph(); return0; } 函数名: setallpallette 功 能: 按指定方式改变所有的调色板颜色 用 法: voidfarsetallpallette(structpalette,far*pallette); 程序例: #include #include #include #include intmain(void) { /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; structpalettetypepal; intcolor,maxcolor,ht; inty=10; charmsg[80]; /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,""); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode! =grOk) /*anerroroccurred*/ { printf("Graphicserror: %s\n",grapherrormsg(errorcode)); printf("Pressanykeytohalt: "); getch(); exit (1);/*terminatewithanerrorcode*/ } maxcolor=getmaxcolor(); ht=2*textheight("W"); /*grabacopyofthepalette*/ getpalette(&pal); /*displaythedefaultpalettecolors*/ for(color=1;color<=maxcolor;color++) { setcolor(color); sprintf(msg,"Color: %d",color); outtextxy(1,y,msg); y+=ht; } /*waitforakey*/ getch(); /*blackoutthecolorsonebyone*/ for(color=1;color<=maxcolor;color++) { setpalette(color,BLACK); getch(); } /*restorethepalettecolors*/ setallpalette(&pal); /*cleanup*/ getch(); closegraph(); return0; } 函数名: setaspectratio 功 能: 设置图形纵横比 用 法: voidfarsetaspectratio(intxasp,intyasp); 程序例: #include #include #include #include intmain(void) { /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; intxasp,yasp,midx,midy; /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,""); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode! =grOk) /*anerroroccurred*/ { printf("Graphicserror: %s\n",grapherrormsg(errorcode)); printf("Pressanykeytohalt: "); getch(); exit (1);/*terminatewithanerrorcode*/ } midx=getmaxx()/2; midy=getmaxy()/2; setcolor(getmaxcolor()); /*getcurrentaspectratiosettings*/ getaspectratio(&xasp,&yasp); /*drawnormalcircle*/ circle(midx,midy,100); getch(); /*claerthescreen*/ cleardevice(); /*adjusttheaspectforawidecircle*/ setaspectratio(xasp/2,yasp); circle(midx,midy,100); getch(); /*adjusttheaspectforanarrowcircle*/ cleardevice(); setaspectratio(xasp,yasp/2); circle(midx,midy,100); /*cleanup*/ getch(); closegraph(); return0; } 函数名: setbkcolor 功 能: 用调色板设置当前背景颜色 用 法: voidfarsetbkcolor(intcolor); 程序例: #include #include #include #include intmain(void) { /*selectadriverandmodethatsupports*/ /*multiplebackgroundcolors. */ intgdriver=EGA,gmode=EGAHI,errorcode; intbkcol,maxcolor,x,y; charmsg[80]; /*initializegraphicsandlocalvariables*/ initgraph(&gdriver,&gmode,""); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode! =grOk) /*anerroroccurred*/ { printf("Graphicserror: %s\n",grapherrormsg(errorcode)); printf("Pressanykeytohalt: "); getch(); exit (1);/*terminatewithanerrorcode*/ } /*maximumcolorindexsupported*/ maxcolor=getmaxcolor(); /*forcenteringtextmessages*/ settextjustify(CENTER_TEXT,CENTER_TEXT); x=getmaxx()/2; y=getmaxy()/2; /*loopthrought
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 函数 大全