C語言函數(shù)大全(s開頭)(一)_第1頁
C語言函數(shù)大全(s開頭)(一)_第2頁
C語言函數(shù)大全(s開頭)(一)_第3頁
C語言函數(shù)大全(s開頭)(一)_第4頁
C語言函數(shù)大全(s開頭)(一)_第5頁
已閱讀5頁,還剩65頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

C語言函數(shù)大全(s開頭)(1)

函數(shù)名:sbrk

功能:改變數(shù)據(jù)段空間位置

用法: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;

)

函數(shù)名:scant

功能:執(zhí)行格式化輸入

用法: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;

)

函數(shù)名: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;

)

函數(shù)名:sector

功能:畫并填充橢圓扇區(qū)

用法: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;

)

函數(shù)名: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;

)

函數(shù)名:setactivepage

功能:設(shè)置圖形輸出活動頁

用法: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;

)

函數(shù)名:setallpallette

功能:按指定方式改變所有的調(diào)色板顏色

用法: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;

)

函數(shù)名:setaspectratio

功能:設(shè)置圖形縱橫比

用法: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;

)

函數(shù)名:setbkcolor

功能:用調(diào)色板設(shè)置當前背景顏色

用法: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;

)

函數(shù)名: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;

)

函數(shù)名:setbuf

功能:把緩沖區(qū)與流相聯(lián)

用法: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;

)

困數(shù)名:setcbrk

功能:設(shè)置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;

)

函數(shù)名:setcolor

功能:設(shè)置當前畫線顏色

用法: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;

)

函數(shù)名:setdate

功能:設(shè)置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;

)

函數(shù)名:setdisk

功能:設(shè)置當前磁盤驅(qū)動器

用法: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;

)

函數(shù)名:setdta

功能:設(shè)置磁盤傳輸區(qū)地址

用法: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;

)

函數(shù)名: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;

)

函數(shù)名:setfillstyle

功能:設(shè)置填充模式和顏色

用法: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;

)

函數(shù)名:setftime

功能:設(shè)置文件日期和時間

用法: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;

}

函數(shù)名:setgraphbufsize

功能:改變內(nèi)部圖形緩沖區(qū)的大小

用法: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;

)

函數(shù)名:setgraphmode

功能:將系統(tǒng)設(shè)置成圖形模式且清屏

用法: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;

)

函數(shù)名:setjmp

功能:非局部轉(zhuǎn)移

用法: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);

}

函數(shù)名:setlinestyle

功能:設(shè)置當前畫線寬度和類型

用法: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;

)

函數(shù)名:setmem

功能:存值到存儲區(qū)

用法: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;

}

函數(shù)名:setmode

功能:設(shè)置打開文件方式

用法: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;

)

函數(shù)名:setpalette

功能:改變調(diào)色板的顏色

用法: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;

)

函數(shù)名: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;

)

函數(shù)名:settextjustify

功能:為圖形函數(shù)設(shè)置文本的對齊方式

用法: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);

}

函數(shù)名:settextstyle

功能:為圖形輸出設(shè)置當前的文本屬性

用法: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;

)

函數(shù)名:settextstyle

功能:為圖形輸出設(shè)置當前的文本屬性

用法: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;

)

函數(shù)名:settime

功能:設(shè)置系統(tǒng)時間

用法: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;

)

函數(shù)名: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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論