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),請進行舉報或認(rèn)領(lǐng)

文檔簡介

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

函數(shù)名:sbrk

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

用法:char*sbrk(intincr);

程序例:

include

#include

intmain(void)

{

printf(nChangingallocationwithsbrk()\nn);

printf(HBeforesbrk()call:%lubytesfree\nH,

(unsignedlong)coreleft());

sbrk(1000);

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

(unsignedlong)coreleft());

return0;

)

函數(shù)名:scanf

功能:執(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(H\n\nPleaseenteralabelforthechart:”);

scanf(',%20s,',label);

fflush(stdin);/*flushtheinputstreamincaseofbadinput*/

/*Inputnumberofentriesasaninteger*/

printf(HHowmanyentrieswilltherebe?(lessthan20)");

scanf("%dM,&entries);

fflush(stdin);/*flushtheinputstreamincaseofbadinput*/

/*inputanamerestrictinginputtoonlylettersupperorlowercase*/

for(loop=0;loop

(

printf("Entry%d\nn,loop);

printf(HName:”);

scanf(H%[A-Za-z]",entry[loop].name);

fflush(stdin);/*flushtheinputstreamincaseofbadinput*/

/*inputanageasaninteger*/

printf(HAge:");

scanf("%dH,&entry[loop].age);

fflush(stdin);/*flushtheinputstreamincaseofbadinput*/

/*inputasalaryasafloat*/

printfCSalary:");

scanf("%f,&entry[loop].salary);

fflush(stdin);/*flushtheinputstreamincaseofbadinput*/

)

/*Inputaname,ageandsalaryasastring,integer,anddouble*/

printf(H\nPleaseenteryourname,ageandsalary\nn);

scanf("%20s%d%lf,name,&age,&salary);

rPrintoutthedatathatwasinput*/

printf(H\n\nTable%s\nH,label);

printf("Compiledby%sage%d$%15.2lf\n",name,age,salary);

printf(M\n");

for(loop=0;loop

printf("%4d|%-20s|%5d|%15.2lf\nH,

loop+1,

entry[loop].name,

entry[loop].age,

entryfloop].salary);

printf(H\nH);

return0;

)

函數(shù)名:searchpath

功能:搜索DOS路徑

用法:char*searchpath(char*filename);

程序例:

include

#include

intmain(void)

{

char*p;

/*LooksforTLINKandreturnsapointer

tothepath*/

p=searchpathCTLINK.EXE");

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

/*Looksfornon-existentfile*/

p=searchpath("NOTEXIST.FILn);

printf(nSearchforNOTEXIST.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(HGraphicserror:%s\n",grapherrormsg(errorcode));

printf(HPressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

midx=getmaxx()/2;

midy=getmaxy()/2;

/*loopthroughthefillpatterns*/

for(i=EMPTY_FILL;i

(

/*setthefillstyle*/

setf川style。,getmaxcolor());

/*drawthesectorslice*/

sector(midx,midy,stangle,endangle,xrad,yrad);

getch();

}

/*cleanup*/

closegraph();

return0;

)

函數(shù)名:segread

功能:讀段寄存器值

用法:voidsegread(structSREGS*segtbl);

程序例:

include

include

intmain(void)

(

structSREGSsegs;

segread(&segs);

printf(HCurrentsegmentregistersettings\n\nH);

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

intgdriver=EGA,gmode=EGAHI,errorcode;

intx,y,ht;

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,,H,);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf(HPressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

x=getmaxx()/2;

y=getmaxy()/2;

ht=textheight(nW");

/*selecttheoffscreenpagefordrawing*/

setactivepage(l);

/*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(O);

routputamessageonpage#0*/

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

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

getch();

rselectpage#1asthevisiblepage*/

setvisualpage(l);

/*cleanup*/

getch();

closegraph();

return0;

}

函數(shù)名:setallpallette

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

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

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

maxcolor=getmaxcolor();

ht=2*textheight(HW");

/*grabacopyofthepalette*/

getpalette(&pal);

/*displaythedefaultpalettecolors*/

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

{

setcolor(color);

sprintf(msg,"Color:%dH,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;

)

函數(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,,H,);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

printf(HGraphicserror:%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;

)

函數(shù)名:setbkcolor

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

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

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf(HPressanykeytohalt:");

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;

s泛e=64;/*(64x16)=1024bytes7

stat=allocmem(size,&segp);

if(stat==-1)

printf(MAllocatedmemoryatsegment:%X\nM,segp);

else

(

printf(HFailed: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\nn);

puts("Thisoutputwillgointooutbuf\n");

puts(Handwon'tappearuntilthebuffer\nn);

puts("fillsuporweflushthestream.\nH);

/*flushtheoutputbuffer*/

fflush(stdout);

return0;

)

函數(shù)名:setcbrk

功能:設(shè)置Control-break

用法:intsetcbrk(intvalue);

程序例:

include

#include

#include

intmain(void)

intbreak_flag;

printf(nEnter0toturncontrolbreakoff\nn);

printf(HEnter1toturncontrolbreakon\nn);

break_flag=getch()-0;

setcbrk(break_flag);

if(getcbrk())

printf("Cntrl-brkflagison\n");

else

printf(HCntrl-brkflagisoff\n");

return0;

)

函數(shù)名:setcolor

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

用法: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(HGraphicserror:%s\n",grapherrormsg(errorcode));

printf(HPressanykeytohalt:");

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

(

rclearthescreen*/

cleardevice();

/*selectanewbackgroundcolor7

setcolor(color);

/*outputamesssage*/

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

outtextxy(x,y,msg);

getch();

}

/*cleanup*/

closegraph();

return0;

)

函數(shù)名:setdate

功能:設(shè)置DOS日期

用法:voidsetdate(structdate*dateblk);

程序例:

//include

include

include

intmain(void)

(

structdatereset;

structdatesave_date;

getdate(&save_date);

printfC'Originaldate:\nn);

system("date");

reset.da_year=2001;

reset.da_day=1;

reset.da_mon=1;

setdate(&reset);

printf(HDateaftersetting:\nH);

system("date");

setdate(&save_date);

printfC'Backtooriginaldate:\nn);

system("date");

return0;

)

函數(shù)名:setdisk

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

用法:intsetdisk(intdrive);

程序例:

#include

include

intmain(void)

intsave,disk,disks;

/*saveoriginaldrive*/

save=getdisk();

/*printnumberoflogicdrives*/

disks=setdisk(save);

printf(n%dlogicaldrivesonthesystem\n\n",disks);

/*printthedrivelettersavailable*/

printf(HAvailabledrives:\nn);

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

(

setdisk(disk);

if(disk==getdisk())

printf("%c:driveisavailable\nH,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!'1;

structfcbblk;

intresult;

/*getnewfilenamefromuser*/

printf(nEnterafilenametocreate:'1);

gets(line);

/*parsethenewfilenametothedta*/

parsfnm(line,&blk,1);

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

/*requestDOSservicestocreatefile*/

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

perror(uErrorcreatingfile");

exit(1);

)

/*saveolddtaandsetnewdta*/

save_dta=getdta();

setdta(buffer);

/*writenewrecords*/

blk.fcb_recsize=256;

blk.fcb_random=OL;

result=randbwr(&blk,1);

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

if(iresult)

printf(HWriteOK\n");

else

(

perror("Diskerror");

exit(1);

)

rrequestDOSservicestoclosethefile*/

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)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intmaxx,maxy;

/*auserdefinedfillpattern*/

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

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,"n);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf(HPressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

maxx=getmaxx();

maxy=getmaxy();

setcolor(getmaxcolor());

/*selectauserdefinedfillpattern*/

setfi11pattern(pattern,getmaxcolor());

/*fillthescreenwiththepattern*/

bar(0,0,maxx,maxy);

/*cleanup*/

getch();

closegraph();

return0;

}

函數(shù)名:setfillstyle

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

用法:voidfarsetfillstyle(intpattern,intcolor);

程序例:

include

include

include

include

include

/*thenamesofthefillstylessupported*/

char*fname[]={nEMPTY_FILL",

HSOLID_FILL",

nLINE_FILLn,

HLTSLASH_FILL",

,'SLASH.FILL",

"BKSLASH.FILL",

HLTBKSLASH_FILLH,

"HATCH_FILLH,

,'XHATCH.FILL",

HINTERLEAVE_FILL",

,'WIDE.DOT.FILL",

"CLOSE_DOT_FILL",

HUSER_FILLH

);

intmain(void)

{

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy;

charstylestr[40];

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,,H,);

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

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

(

/*selectthefillstyle*/

setfillstyle(style,getmaxcolor());

/*convertstyleintoastring*/

strcpy(stylestr,fname[style]);

/*fillabar*/

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

routputamessage*/

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("TEST.$$$n,Hw"))==NULL)

perror('^Error:,,);

exit(1);

}

fprintf(fp,"testing...\nn);

rloadftimestructurewithnewtimeanddate*/

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

system(ndirTEST.$$$");

/*changethetimeanddatestamp*/

setftime(fileno(fp),&filet);

/*closeandremovethetemporaryfile*/

fclose(fp);

system("dirTEST.$$$");

unlink("TEST.$$$n);

return0;

}

函數(shù)名:setgraphbufsize

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

用法:unsignedfarsetgraphbufsize(unsignedbufsize);

程序例:

include

include

include

include

#defineBUFSIZE1000/*internalgraphicsbuffersize*/

intmain(void)

{

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intx,y,oldsize;

charmsg[80];

/*setthesizeoftheinternalgraphicsbuffer*/

/*beforemakingacalltoinitgraph.*/

oldsize=setgraphbufsize(BUFSIZE);

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,,m);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

printf(HGraphicserror:%s\nn,grapherrormsg(errorcode));

printf(HPressanykeytohalt:");

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:%dH,oldsize);

outtextxy(x,y+textheight("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,m,);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

x=getmaxx()/2;

y=getmaxy()/2;

/*outputamessage*/

settextjustify(CENTER_TEXT,CENTER_TEXT);

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

getch();

/*restoresystemtotextmode*/

restorecrtmode();

printf(HWe'renowintextmodeAn");

printf(,,Pressanykeytoreturntographicsmode:");

getch();

/*returntographicsmode*/

setgraphmode(getgraphmode());

/*outputamessage*/

settextjustify(CENTER_TEXT,CENTER_TEXT);

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

outtextxy(x,y+textheight(nW"),"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(HLongjmpwithvalue%d\nH,value);

exit(value);

)

printf(nAbouttocallsubroutine...\n");

subroutine();

return0;

)

voidsubroutine(void)

Iongjmp(jumper,1);

)

函數(shù)名:setlinestyle

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

用法:voidfarsetlinestyle(intlinestype,unsignedupattern);

程序例:

include

include

//include

include

include

rthenamesofthelinestylessupported7

char*lname[]={

HSOLID_LINEH,

"DOTTED_LINEH,

HCENTER_LINEH,

"DASHED_LINEH,

nUSERBIT_LINE'

);

intmain(void)

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy,userpat;

charstylestr[40];

rinitializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,,H,);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf(HPressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

midx=getmaxx()/2;

midy=getmaxy()/2;

/*auserdefinedlinepattern*/

rbinary:n0000000000000001"*/

userpat=1;

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

{

/*selectthelinestyle*/

setlinestyle(style,userpat,1);

/*convertstyleintoastring*/

strcpy(stylestr,lname[style]);

/*drawaline*/

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

/*drawarectangle*/

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

/*outputamessage*/

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

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

else

printff'Modesuccessfullyswitched\n");

return0;

}

函數(shù)名:setpalette

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

用法:voidfarsetpalette(intindex,intactural_color);

程序例:

include

include

//include

include

intmain(void)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intcolor,maxcolor,ht;

inty=10;

charmsg[80];

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,m,);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

printf("Graphicserror:%s\nn,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*1

getch();

/*blackoutthecolorsonebyone*/

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

(

setpalette(color,BLACK);

getch();

)

I*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,

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf(HPressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

)

/*grabacopyofthepalette*/

getpalette(&pal);

/*creategrayscale*/

for(i=0;i

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

rdisplaythegrayscale*/

ht=getmaxy()/16;

xmax=getmaxx();

y=o;

for(i=0;i

(

setfillstyle(SOLID_FILL,i);

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

y+=ht;

)

/*cleanup*/

getch();

closegraph();

return0;

)

函數(shù)名:settextjustify

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

用法:voidfarsettextjustify(inthoriz,intvert);

程序例:

include

include

#include

include

rfunctionprototype*/

voidxat(intx,inty);

/*horizontaltextjustificationsettings*/

char*hjustQ={"LEFT_TEXT",

nCENTER_TEXT",

"RIGHT_TEXTn

};

/*verticaltextjustificationsettings*/

char*vjust[]={“LEFT_TEXT”,

HCENTER_TEXT",

"RIGHT_TEXTn

);

intmain(void)

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intmidx,midy,hj,vj;

charmsg[80];

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

rreadresultofinitialization*/

errorcode=graphresult();

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

{

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

printf(HPressanykeytohalt:");

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,H%s%s",hjust[hj],vjust[vj]);

rcreatecrosshairsonthescreen*/

xat(midx,midy);

/*outputthemessage*/

outtextxy(midx,midy,msg);

getch();

)

/*cleanup*/

closegraph();

return0;

)

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

voidxat(intx,inty)

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

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

)

函數(shù)名:settextstyle

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

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

程序例:

include

include

//include

include

/*thenamesofthetextstylessupported7

char*fname[]={"DEFAULTfont”,

,'TRIPLEXfont',,

,'SMALLfont1',

"SANSSERIFfont",

"GOTHICfont'1

};

intmain(void)

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy;

intsize=1;

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,,m);

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf(HPressanykeytohalt:");

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

settextstyle(style,HORIZ_DIR,size);

/*outputamessage*/

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

getch();

)

/*cleanup*/

closegraph();

return0;

)

函數(shù)名:settextstyle

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

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

程序例:

#include

#include

include

#include

/*thenamesofthetextstylessupported*/

char*fname[]={"DEFAULTfont”,

,'TRIPLEXfont'1,

"SMALLfont1',

“SANSSERIFfont",

"GOTHICfont'1

);

intmain(void)

(

/*requestautodetection*/

intgdriver=DETECT,gmode,errorcode;

intstyle,midx,midy;

intsize=1;

/*initializegraphicsandlocalvariables*/

initgraph(&gdriver,&gmode,

/*readresultofinitialization*/

errorcode=graphresult();

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

printf(HGraphicserror:%s\nn,grapherrormsg(errorcode));

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

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\n”,t.ti_sec);

/*Addonetotheminutesstructelementandthencallsettime*/

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

/*readresultofinitialization*/

errorcode=graphresult();

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

(

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

printf("Pressanykeytohalt:");

getch();

exit(1);/*terminatewithanerrorcode*/

}

/*selectate

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論