S开头函数.docx
- 文档编号:9013978
- 上传时间:2023-05-16
- 格式:DOCX
- 页数:87
- 大小:40.45KB
S开头函数.docx
《S开头函数.docx》由会员分享,可在线阅读,更多相关《S开头函数.docx(87页珍藏版)》请在冰点文库上搜索。
S开头函数
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
{
charname[20];
intage;
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%sage%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: %XDS: %X\n",segs.cs,segs.ds); printf("ES: %XSS: %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); /*outputamessageonpage#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; /*loopthroughtheavailablecolors*/ for(bkcol=0;bkcol<=maxcolor;bkcol++) { /*clearthescreen*/ cleardevice(); /*selectanewbackgroundcolor*/ setbkcolor(bkcol); /*outputamesssage*/ if(bkcol==WHITE) setcolor(EGA_BLUE); sprintf(msg,"Backgroundcolor: %d",bkcol); outtextxy(x,y,msg); getch(); } /*cleanup*/ closegraph(); return0; } 函数名: setblock 功能: 修改先前已分配的DOS存储段大小 用法: intsetblock(intseg,intnewsize); 程序例: #include #include #include #include intmain(void) { unsignedintsize,segp; intstat; size=64;/*(64x16)=1024bytes*/ stat=allocmem(size,&segp); if(stat==-1) printf("Allocatedmemoryatsegment: %X\n",segp); else { printf("Failed: maximumnumberofparagraphsavailableis%d\n", stat); exit (1); } stat=setblock(segp,size*2); if(stat==-1) printf("Expandedmemoryblockatsegment: %X\n",segp); else printf("Failed: maximumnumberofparagraphsavailableis%d\n", stat); freemem(segp); return0; } 函数名: setbuf 功能
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 开头 函数