C语言函数大全S.docx

上传人:b****5 文档编号:28472168 上传时间:2023-07-14 格式:DOCX 页数:71 大小:32.55KB
下载 相关 举报
C语言函数大全S.docx_第1页
第1页 / 共71页
C语言函数大全S.docx_第2页
第2页 / 共71页
C语言函数大全S.docx_第3页
第3页 / 共71页
C语言函数大全S.docx_第4页
第4页 / 共71页
C语言函数大全S.docx_第5页
第5页 / 共71页
点击查看更多>>
下载资源
资源描述

C语言函数大全S.docx

《C语言函数大全S.docx》由会员分享,可在线阅读,更多相关《C语言函数大全S.docx(71页珍藏版)》请在冰豆网上搜索。

C语言函数大全S.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1