C语言函数大全(s开头)(一)_第1页
C语言函数大全(s开头)(一)_第2页
C语言函数大全(s开头)(一)_第3页
C语言函数大全(s开头)(一)_第4页
C语言函数大全(s开头)(一)_第5页
已阅读5页,还剩65页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C语言函数大全(s开头)(1)

函数名:sbrk

功能:改变数据段空间位置

用法:char*sbrk(intincr);

程序例:

/include

/include

intmain(void)

{

printf("Changingallocationwithsbrk()\n");

printf("Beforesbrk()call:%lubytesfree\n",

(unsignedlong)coreleft());

sbrk(WOO);

printf("Aftersbrk()call:%lubytesfree\n",

(unsignedlong)coreleft());

return0;

)

函数名:scant

功能:执行格式化输入

用法: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*/

rinputasalaryasafloat*/

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);

/*Printoutthedatathatwasinput7

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;

I*LooksforTLINKandreturnsapointer

tothepath*/

p=searchpath("TLINK.EXEH);

printf("SearchforTLINK.EXE:%s\n".p);

rLooksfornon-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\nn,grapherrormsg(errorcodei);

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,stangls,endangle,xrad,yrad);

getch();

)

rcleanup*/

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.7

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(l);

/*drawalineonpage#1*/

line(0,0,getmaxx(),getmaxyO);

routputamessageonpage#1w/

settextjustify(CENTER_TEXT,CENTER_TEXT);

outtextxy(x,y,"Thisispage#1

outtextxy(x,y+ht,"Pressanykeytohalt:");

/*selectdrawingtopage#0*/

setactivepage(O);

routputamessageonpage#0*/

outtextxy(x,y,"Thisispage#0.");

outtextxy(x,y+ht,"Pressanykeytoviewpage#1

getch();

/*selectpage#1asthevisiblepage*/

setvisualpage(l);

/*cleanup*/

getch();

closegraph();

return0;

)

函数名:setallpallette

功能:按指定方式改变所有的调色板颜色

用法:voidfarsetallpallette(structpalette,far*pallette);

程序例:

/include

include

/include

/include

intmain(void)

(

rrequestautodetection*/

intgdriver=DETECT,gmode,errorcode;

structpalettetypepal;

intcolor,maxcolor,ht;

inty=10;

charmsg[80];

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization7

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\n",grapherrormsg(errorcode));

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode7

)

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);

rcleanup*/

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,

rreadresultofinitialization*/

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);

rdrawnormalcircle7

circle(midx,midy,100);

getch();

/*claerthescreen*/

cleardevice();

/*adjusttheaspectforawidecircle*/

setaspectratio(xasp/2,yasp);

circle(midx,midy,100);

getch();

/*adjusttheaspectforanarrowcircle*/

cleardevice();

setaspectratio(xasp,yasp/2);

circlefmidx,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

功能:把缓冲区与流相联

用法:voidsetbuf(FILE*steam,char*buf);

程序例:

include

/*BUFSIZisdefinedinstdio.h*/

charoutbuf[BUFSIZ];

intmain(void)

/*attachabuffertothestandardoutputstream*/

setbuf(stdout,outbuf);

/*putsomecharactersintothebuffer*/

puts("Thisisatestofbufferedoutput.\n\n");

puts("Thisoutputwillgointooutbuf\n");

puts("andwon'tappearuntilthebuffer\nM);

puts("fillsuporweflushthestreamAn");

/*flushtheoutputbuffer7

fflush(stdout);

return0;

)

困数名:setcbrk

功能:设置Control-break

用法:intsetcbrk(intvalue);

程序例:

include

//include

include

intmain(void)

intbreak_flag;

printf("Enter0toturncontrolbreakoff\n");

printf("Enter1toturncontrolbreakon\n");

break_flag=getch()-0;

setcbrk(break_flag);

if(getcbrk())

printf("Cntrl-brkflagison\n");

else

printf("Cntrl-brkflagisoffn");

return0;

)

函数名:setcolor

功能:设置当前画线颜色

用法:voidfarsetcolor(intcolor);

程序例:

//include

include

include

include

intmain(void)

(

/*selectadriverandmodethatsupports*/

/*multipledrawingcolors.*/

intgdriver=EGA,gmode=EGAHI,errorcode;

intcolor,maxcolor,x,y;

charmsg[80];

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\nH,grapherrormsg(errorcodej);

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

/*maximumcolorindexsupported*/

maxcolor=getmaxcolor();

/*forcenteringtextmessages*/

settextjustify(CENTER_TEXT,CENTER_TEXT);

x=getmaxx()/2;

y=getmaxy()/2;

/*loopthroughtheavailablecolors*/

for(color=1;color<=maxcolor;color++)

(

/*clearthescreen*/

cleardevice();

/*selectanewbackgroundcolor*/

setcolor(color);

/*outputamesssage*/

sprintf(msg,"Color:%d",color);

outtextxy(x,y,msg);

getch();

)

/*cleanup*/

closegraph();

return0;

)

函数名:setdate

功能:设置DOS日期

用法:voidsetdate(struddate*dateblk);

程序例:

include

/include

include

intmain(void)

(

structdatereset;

structdatesave_date;

getdate(&save_date);

printf("Originaldate:\n");

system("date");

reset.da_year=2001;

reset.da_day=1;

reset.da_mon=1;

setdate(&reset);

printf("Dateaftersetting:\n");

system("date");

setdate(&save_date);

printf("Backtooriginaldate:\n");

system("date");

return0;

)

函数名:setdisk

功能:设置当前磁盘驱动器

用法:intsetdisk(intdrive);

程序例:

/include

/include

intmain(void)

intsave,disk,disks;

/*saveoriginaldrive*/

save=getdisk();

/*printnumberoflogicdrives*/

disks=setdisk(save);

printf("%dlogicaldrivescnthesystem\n\n'\disks);

/*printthedrivelettersavailable*/

printf("Availabledrives:\n");

for(disk=0;disk<26;++disk)

(

setdisk(disk);

if(disk==getdisk())

printf("%c:driveisavailable\n",disk+'a');

)

setdisk(save);

return0;

)

函数名:setdta

功能:设置磁盘传输区地址

用法:voidsetdta(charfar*dta);

程序例:

//include

include

include

include

intmain(void)

(

charline[80],far*save_dta;

charbuffer[256]="SETDTAtest!”;

structfcbblk;

intresult;

/*getnewfilenamefromuser*/

printf("Enterafilenametocreate:");

gets(line);

/*parsethenewfilenametothedta*/

parsfnm(line,&blk,1);

printf("%d%s\n",blk.fcb_drive,blk.fcb_name);

/*requestDOSservicestocreatefile*/

if(bdosptr(0x16,&blk,0)==-1)

perror("Errorcreatingfile');

exit(1);

)

/*saveolddtaandsetnewdta*/

save_dta=getdta();

setdta(buffer);

/*writenewrecords7

blk.fcb_recsize=256;

blk.fcb_random=OL;

result=randbwr(&blk,1);

printf("result=%d\n",result);

if(Jresult)

printf("WriteOK\n");

else

(

perror("Diskerror");

exit(1);

)

/*requestDOSservicestoclosethefile*/

if(bdosptr(0x10,&blk,0)==-1)

perror("Errorclosingfile");

exit(1);

)

/*resettheolddta*/

setdta(save_dta);

return0;

)

函数名:setfillpattern

功能:选择用户定义的填充模式

用法:voidfarsetfillpattern(charfar*upattern,intcolor);

程序例:

include

include

include

include

intmain(void)

(

I*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intmaxx,maxy;

/*auserdefinedfillpattern*/

charpattern[8]={0x00,0x70,0x20,0x27,0x24,0x24,0x07,0x00};

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\n",grapherrormsg(errorcode));

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

maxx=getmaxx();

maxy=getmaxy();

setcolor(getmaxcolor());

/*selectauserdefinedfillpattern*/

setfillpattern(pattern,getmaxcolor());

/*fillthescreenwiththepattern*/

bar(0,0,maxx,maxy);

/*cleanup*/

getch();

closegraph();

return0;

)

函数名:setfillstyle

功能:设置填充模式和颜色

用法:voidfarsetfillstylelintpattern,intcolor);

程序例:

/include

include

/include

/include

include

/*thenamesofthefillstylessupported*/

char*fnameO={"EMPTY_FILL",

"SOLID_FILL",

"LINE_FILLH,

"LTSLASH.FILL*',

"SLASH_FILL",

"BKSLASHFILL",

"LTBKSLASH.FILL",

"HATCH_FILL",

"XHATCH_FILLH,

"INTERLEAVE_FILL';

"WIDE_DOT_FILLM,

"CLOSE_DOT_FILL",

"USER.FILL"

);

intmain(void)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy;

charstylestr[40];

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

printf("Graphicserror:%s\n",grapherrormsg(errorcodei);

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

midx=getmaxx()/2;

midy=getmaxy()/2;

for(style=EMPTY_FILL;style<USER_FILL;style++)

(

/*selectthefillstyle*/

setfillstyle(style,getmaxc3lor());

/*convertstyleintoastring*/

strcpy(stylestr,fname[style]);

/*fillabar*/

bar3d(0,0,midx-10,midy,0,0);

/*outputamessage*/

outtextxy(midx,midy,stylestr);

/*waitforakey*/

getch();

cleardevice();

)

/*cleanup*/

getch();

closegraph();

return0;

)

函数名:setftime

功能:设置文件日期和时间

用法:intsetftime(inthandle,structftime*ftimep);

程序例:

include

include

include

include

intmain(void)

(

structftimefilet;

FILE*fp;

if((fp=fopen(nTEST.$$$","wH))==NULL)

perror("Error:");

exit(1);

)

fprintf(fp,"testing..An");

/*loadftimestructurewithnewtimeanddate*/

filet.ft_tsec=1;

filet.ft_min=1;

filet.ft_hour=1;

filet.ft_day=1;

filet.ft_month=1;

filet.ft_year=21;

/*showcurrentdirectoryfortimeanddate*/

systemf'dirTEST.$$$");

/*changethetimeanddatestamp*/

setftime(fileno(fp),&filet);

/*closeandremovethetemporaryfile*/

fclose(fp);

system("dirTEST.$$$H);

unlink("TEST.$$$");

return0;

}

函数名:setgraphbufsize

功能:改变内部图形缓冲区的大小

用法:unsignedfarsetgraphbufsize(unsignedbufsize);

程序例:

include

include

/include

include

#defineBUFSIZE1000/*internalgraphicsbuffersize7

intmain(void)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intx,y,oldsize;

charmsg[80];

/*setthesizeoftheinternalgraphicsbuffer*/

/*beforemakingacalltoinitgraph.*/

oldsize=setgraphbufsize(BUFSIZE);

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\n",grapherrormsg(errorcodei);

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

x=getmaxx()/2;

y=getmaxy()/2;

/*outputsomemessages*/

sprintf(msg,"Graphicsbuffersize:%d",BUFSIZE);

settextjustify(CENTER_TEXT,CENTER_TEXT);

outtextxy(x,y,msg);

sprintf(msg,"Oldgraphicsbuffersize:%d",oldsize);

outtextxy(x,y+textheightf'W"),msg);

/*cleanup*/

getch();

closegraph();

return0;

)

函数名:setgraphmode

功能:将系统设置成图形模式且清屏

用法:voidfarsetgraphmode(intmode);

程序例:

include

include

/include#include

intmain(void)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intx,y;

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization7

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\n",grapherrormsg(errorcode));

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode7

)

x=getmaxx()/2;

y=getmaxy()/2;

/*outputamessage*/

settextjustify(CENTER_TEXT,CENTER_TEXT);

outtextxy(x,y,"Pressanykeytoexitgraphics:");

getch();

/*restoresystemtotextmode*/

restorecrtmode();

printf("We'renowintextmodeAn");

printf("Pressanykeytoreturntographicsmode:");

getch();

/*returntographicsmode*/

setgraphmode(getgraphmode());

/*outputamessage*/

settextjustify(CENTER_TEXT,CENTER_TEXT);

outtextxy(x,y,"We'rebackingraphicsmode.");

outtextxy(x,y+textheightf'W"),"Pressanykeytohalt:");

/*cleanup*/

getch();

closegraph();

return0;

)

函数名:setjmp

功能:非局部转移

用法:intsetjmp(jmp_bufenv);

程序例:

//include

include

include

voidsubroutine(void);

jmp_bufjumper;

intmain(void)

(

intvalue;

value=setjmp(jumper);

if(value!=0)

(

printf("Longjmpwithvalue%d\n",value);

exit(value);

)

printf("Abouttocallsubroutine...\n");

subroutine();

return0;

)

voidsubroutine(void)

longjmpGumper,1);

}

函数名:setlinestyle

功能:设置当前画线宽度和类型

用法:voidfarsetlinestyle(intlinestype,unsignedupattern);

程序例:

include

include

include

/include

include

/*thenamesofthelinestylessupported*/

char*lname[]={

"SOLID_LINE",

"DOTTED_LINE",

"CENTER.LINE",

"DASHED_LINE",

"USERBIT.LINE"

);

intmain(void)

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy,userpat;

charstylestr[40];

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\n",grapherrormsg(errorcodei);

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

}

midx=getmaxx()/2;

midy=getmaxy()/2;

/*auserdefinedlinepattern*/

/*binary:"00000000000C0001"*/

userpat=1;

for(style=SOLID_LINE;style<=USERBIT_LINE;style++)

(

/*selectthelinestyle*/

setlinestyle(style,userpat,1);

/*convertstyleintoastring7

strcpy(stylestr,lname[style]);

/*drawaline*/

line(0,0,midx-10,midy);

/*drawarectangle*/

rectangle(0,0,getmaxx(),getmaxy());

routputamessage*/

outtextxy(midx,midy,stylestr);

/*waitforakey*/

getch();

cleardevice();

)

/*cleanup*/

closegraph();

return0;

)

函数名:setmem

功能:存值到存储区

用法:voidsetmem(void*addr,intlen,charvalue);

程序例:

/include

include

include

intmain(void)

(

char*dest;

dest=calloc(21,sizeof(cnar));

setmem(dest,20,'c');

printf("%s\n",dest);

return0;

}

函数名:setmode

功能:设置打开文件方式

用法:intsetmode(inthandle,unsignedmode);

程序例:

include

include

include

intmain(void)

(

intresult;

result=setmode(fileno(stdprn),O_TEXT);

if(result==-1)

perror("Modenotavailable\n");

else

printf("Modesuccessfullyswitched\n");

return0;

)

函数名:setpalette

功能:改变调色板的颜色

用法:voidfarsetpalettetintindex,intactural_color);

程序例:

include

include

include

include

intmain(void)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

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");

/*displaythedefaultcolors*/

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();

}

/*cleanup*/

closegraph();

return0;

)

函数名:setrgbpalette

功能:定义旧M8514图形卡的颜色

用法:voidfarsetrgbpalette(intcolornum,intred,intgreen,intblue);

程序例:

include

include

/include

include

intmain(void)

/*selectadriverandmodethatsupportstheuse*/

/*ofthesetrgbpalettefunction.*/

intgdriver=VGA,gmode=VGAHI,errorcode;

structpalettetypepal;

inti,ht,y,xmax;

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization7

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\nH,grapherrormsg(errorcodei);

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

/*grabacopyofthepalette*/

getpalette(&pal);

/*creategrayscale*/

for(i=0;i

setrgbpalette(pal.colors[i],i*4,i*4,i*4);

/*displaythegrayscale*/

ht=getmaxy()/16;

xmax=getmaxx();

y=o;

for(i=0;i

(

setfillstyle(SOLID_FILL,i);

bar(0,y,xmax,y+ht);

y+=ht;

)

I*cleanup*/

getch();

closegraph();

return0;

)

函数名:settextjustify

功能:为图形函数设置文本的对齐方式

用法:voidfarsettextjustify(inthoriz,intvert);

程序例:

include

include

include

include

/*functionprototype*/

voidxat(intx,inty);

/*horizontaltextjustificationsettings*/

char*hjust[]={MLEFT_TEXT",

"CENTER_TEXT",

"RIGHT.TEXT'

);

/*verticaltextjustificationsettings*/

char*vjust[]={"LEFT_TEXT",

"CENTER_TEXT",

"RIGHT_TEXT”

);

intmain(void)

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intmidx,midy,hj,vj;

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*/

)

midx=getmaxx()/2;

midy=getmaxy()/2;

/*loopthroughtextjustifications*/

for(hj=LEFT_TEXT;hj<=RIGHT_TEXT;hj++)

for(vj=LEFT_TEXT;vj<=RIGHT_TEXT;vj++)

cleardevice();

/*setthetextjustification*/

settextjustify(hj,vj);

/*createamessagestring*/

sprintf(msg,"%s%s",hjust[hj],vjust[vj]);

/*createcrosshairsonthescreen*/

xat(midx,midy);

/*outputthemessage7

outtextxy(midx,midy,msg);

getch();

)

/*cleanup*/

closegraph();

return0;

)

/*drawan"xMat(x,y)*/

voidxat(intx,inty)

line(x-4,y,x+4,y);

Iine(x,y-4,x,y+4);

}

函数名:settextstyle

功能:为图形输出设置当前的文本属性

用法:voidfarsettextstyls(intfont,intdirection,charsize);

程序例:

include

include

include

include

/*thenamesofthetextstylessupported*/

char*fnameQ={"DEFAULTfont",

"TRIPLEXfont",

"SMALLfont",

"SANSSERIFfont",

"GOTHICfont"

};

intmain(void)

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy;

intsize=1;

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\n",grapherrormsg(errorcodei);

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

midx=getmaxx()/2;

midy=getmaxy()/2;

settextjustify(CENTER_TEXT,CENTER_TEXT);

/*loopthroughtheavailabletextstyles*/

for(style=DEFAULT_FONT;style<=GOTHIC_FONT;style++)

cleardevice();

if(style==TRIPLEX_FONT)

size=4;

/*selectthetextstyle*/

settextstylefstyle,HORIZ_DIR,size);

/*outputamessage*/

outtextxy(midx,midy,fname[style]);

getch();

)

/*cleanup*/

closegraph();

return0;

)

函数名:settextstyle

功能:为图形输出设置当前的文本属性

用法:voidfarsettextstyls(intfont,intdirection,charsize);

程序例:

/include

include

//include

include

/*thenamesofthetextstylessupported*/

char*fname[]={"DEFAULTfont1',

"TRIPLEXfont",

"SMALLfont",

"SANSSERIFfont'1,

"GOTHICfont"

);

intmain(void)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy;

intsize=1;

rinitializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

printf("Graphicserror:%s\n",grapherrormsg(errorcodei);

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

}

midx=getmaxx()/2;

midy=getmaxy()/2;

settextjustify(CENTERTEXT,CENTERTEXT);

rloopthroughtheavailabletextstyles*/

for(style=DEFAULT_FONT;style<=GOTHIC_FONT;style++)

(

cleardevice();

if(style==TRIPLEX_FONT)

size=4;

rselectthetextstyle*/

settextstyle(style,HORIZ_DIR,size);

/*outputamessage*/

outtextxy(midx,midy,fname[style]);

getch();

)

/*cleanup*/

closegraph();

return0;

)

函数名:settime

功能:设置系统时间

用法:voidsettime(structtime*timep);

程序例:

/include

include

intmain(void)

(

structtimet;

gettime(&t);

printf("Thecurrentminuteis:%d\nH,t.ti_min);

printf("Thecurrenthouris:%d\n",t.ti_hour);

printf("Thecurrenthundredthofasecondis:%d\n",t.ti_hund);

printf("Thecurrentsecondis:%d\nH,t.ti_sec);

/*Addonetotheminutesstructelementandthencallsettime*/

t.ti_min++;

settime(&t);

return0;

)

函数名:setusercharsize

功能:为矢量字体改变字符宽度和高度

用法:voidfarsetusercharsize(intmultx,intdirx,intmulty,intdiry);

程序例:

include

/include

include

include

intmain(void)

{

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

if(errorcode!=grOk)/*anerroroccurred*/

(

printf("Graphicserror:%s\n",grapherrormsg(errorcode));

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

/*selecta

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论