C语言函数大全P.docx

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

C语言函数大全P.docx

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

C语言函数大全P.docx

C语言函数大全P

函数名:

parsfnm

功 能:

分析文件名

用 法:

char*parsfnm(char*cmdline,structfcb*fcbptr,intoption);

程序例:

#include

#include

#include

#include

intmain(void)

{

  charline[80];

  structfcbblk;

  /*getfilename*/

  printf("Enterdriveandfilename(nopath-ie.a:

file.dat)\n");

  gets(line);

  /*putfilenameinfcb*/

  if(parsfnm(line,&blk,1)==NULL)

     printf("Errorinparsfmcall\n");

  else

     printf("Drive#%d Name:

%11s\n",blk.fcb_drive,blk.fcb_name);

  return0;

}

 

 

函数名:

peek

功 能:

检查存储单元

用 法:

intpeek(intsegment,unsignedoffset);

程序例:

#include

#include

#include

intmain(void)

{

  intvalue=0;

  printf("Thecurrentstatusofyourkeyboardis:

\n");

  value=peek(0x0040,0x0017);

  if(value&1)

     printf("Rightshifton\n");

  else

     printf("Rightshiftoff\n");

  if(value&2)

     printf("Leftshifton\n");

  else

     printf("Leftshiftoff\n");

  if(value&4)

     printf("Controlkeyon\n");

  else

     printf("Controlkeyoff\n");

  if(value&8)

     printf("Altkeyon\n");

  else

     printf("Altkeyoff\n");

  if(value&16)

     printf("Scrolllockon\n");

  else

     printf("Scrolllockoff\n");

  if(value&32)

     printf("Numlockon\n");

  else

     printf("Numlockoff\n");

  if(value&64)

     printf("Capslockon\n");

  else

     printf("Capslockoff\n");

  return0;

}

 

 

函数名:

peekb

功 能:

检查存储单元

用 法:

charpeekb(intsegment,unsignedoffset);

程序例:

#include

#include

#include

intmain(void)

{

  intvalue=0;

  printf("Thecurrentstatusofyourkeyboardis:

\n");

  value=peekb(0x0040,0x0017);

  if(value&1)

     printf("Rightshifton\n");

  else

     printf("Rightshiftoff\n");

  if(value&2)

     printf("Leftshifton\n");

  else

     printf("Leftshiftoff\n");

  if(value&4)

     printf("Controlkeyon\n");

  else

     printf("Controlkeyoff\n");

  if(value&8)

     printf("Altkeyon\n");

  else

     printf("Altkeyoff\n");

  if(value&16)

     printf("Scrolllockon\n");

  else

     printf("Scrolllockoff\n");

  if(value&32)

     printf("Numlockon\n");

  else

     printf("Numlockoff\n");

  if(value&64)

     printf("Capslockon\n");

  else

     printf("Capslockoff\n");

  return0;

}

 

 

函数名:

perror

功 能:

系统错误信息

用 法:

voidperror(char*string);

程序例:

#include

intmain(void)

{

  FILE*fp;

  fp=fopen("perror.dat","r");

  if(!

fp)

     perror("Unabletoopenfileforreading");

  return0;

}

 

 

函数名:

pieslice

功 能:

绘制并填充一个扇形

用 法:

voidfarpieslice(intx,intstanle,intendangle,intradius);

程序例:

#include

#include

#include

#include

intmain(void)

{

  /*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  intmidx,midy;

  intstangle=45,endangle=135,radius=100;

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

  /*setfillstyleanddrawapieslice*/

  setfillstyle(EMPTY_FILL,getmaxcolor());

  pieslice(midx,midy,stangle,endangle,radius);

  /*cleanup*/

  getch();

  closegraph();

  return0;

}

 

 

函数名:

poke

功 能:

存值到一个给定存储单元

用 法:

voidpoke(intsegment,intoffset,intvalue);

程序例:

#include

#include

intmain(void)

{

  clrscr();

  cprintf("Makesurethescrolllockkeyisoffandpressanykey\r\n");

  getch();

  poke(0x0000,0x0417,16);

  cprintf("Thescrolllockisnowon\r\n");

  return0;

}

 

 

函数名:

pokeb

功 能:

存值到一个给定存储单元

用 法:

voidpokeb(intsegment,intoffset,charvalue);

程序例:

#include

#include

intmain(void)

{

  clrscr();

  cprintf("Makesurethescrolllockkeyisoffandpressanykey\r\n");

  getch();

  pokeb(0x0000,0x0417,16);

  cprintf("Thescrolllockisnowon\r\n");

  return0;

}

 

 

函数名:

poly

功 能:

根据参数产生一个多项式

用 法:

doublepoly(doublex,intn,doublec[]);

程序例:

#include

#include

/*polynomial:

 x**3-2x**2+5x-1*/

intmain(void)

{

  doublearray[]={-1.0,5.0,-2.0,1.0};

  doubleresult;

  result=poly(2.0,3,array);

  printf("Thepolynomial:

x**3-2.0x**2+5x-1at2.0is%lf\n",

          result);

  return0;

}

 

 

函数名:

pow

功 能:

指数函数(x的y次方)

用 法:

doublepow(doublex,doubley);

程序例:

#include

#include

intmain(void)

{

  doublex=2.0,y=3.0;

  printf("%lfraisedto%lfis%lf\n",x,y,pow(x,y));

  return0;

}

 

函数名:

pow10

功 能:

指数函数(10的p次方)

用 法:

doublepow10(intp);

程序例:

#include

#include

intmain(void)

{

  doublep=3.0;

  printf("Tenraisedto%lfis%lf\n",p,pow10(p));

  return0;

}

 

 

函数名:

printf

功 能:

产生格式化输出的函数

用 法:

intprintf(char*format...);

程序例:

#include

#include

#defineI555

#defineR5.5

intmain(void)

{

  inti,j,k,l;

  charbuf[7];

  char*prefix=buf;

  chartp[20];

  printf("prefix 6d     6o     8x       10.2e       "

         "10.2f\n");

  strcpy(prefix,"%");

  for(i=0;i<2;i++)

  {

     for(j=0;j<2;j++)

        for(k=0;k<2;k++)

    for(l=0;l<2;l++)

           {

              if(i==0) strcat(prefix,"-");

              if(j==0) strcat(prefix,"+");

              if(k==0) strcat(prefix,"#");

              if(l==0) strcat(prefix,"0");

              printf("%5s|",prefix);

              strcpy(tp,prefix);

              strcat(tp,"6d|");

              printf(tp,I);

              strcpy(tp,"");

              strcpy(tp,prefix);

              strcat(tp,"6o|");

              printf(tp,I);

              strcpy(tp,"");

              strcpy(tp,prefix);

              strcat(tp,"8x|");

              printf(tp,I);

              strcpy(tp,"");

              strcpy(tp,prefix);

       strcat(tp,"10.2e|");

       printf(tp,R);

       strcpy(tp,prefix);

       strcat(tp,"10.2f|");

       printf(tp,R);

       printf(" \n");

       strcpy(prefix,"%");

    }

      }

  return0;

}

 

 

函数名:

putc

功 能:

输出一字符到指定流中

用 法:

intputc(intch,FILE*stream);

程序例:

#include

intmain(void)

{

  charmsg[]="Helloworld\n";

  inti=0;

  while(msg[i])

     putc(msg[i++],stdout);

  return0;

}

 

 

函数名:

putch

功 能:

输出字符到控制台

用 法:

intputch(intch);

程序例:

#include

#include

intmain(void)

{

  charch=0;

  printf("Inputastring:

");

  while((ch!

='\r'))

  {

     ch=getch();

     putch(ch);

  }

  return0;

}

 

 

函数名:

putchar

功 能:

在stdout上输出字符

用 法:

intputchar(intch);

程序例:

#include

/*definesomebox-drawingcharacters*/

#defineLEFT_TOP 0xDA

#defineRIGHT_TOP0xBF

#defineHORIZ    0xC4

#defineVERT     0xB3

#defineLEFT_BOT 0xC0

#defineRIGHT_BOT0xD9

intmain(void)

{

  chari,j;

  /*drawthetopofthebox*/

  putchar(LEFT_TOP);

  for(i=0;i<10;i++)

     putchar(HORIZ);

  putchar(RIGHT_TOP);

  putchar('\n');

  /*drawthemiddle*/

  for(i=0;i<4;i++)

  {

     putchar(VERT);

     for(j=0;j<10;j++)

        putchar('');

     putchar(VERT);

     putchar('\n');

  }

  /*drawthebottom*/

  putchar(LEFT_BOT);

  for(i=0;i<10;i++)

     putchar(HORIZ);

  putchar(RIGHT_BOT);

  putchar('\n');

  return0;

}

 

 

函数名:

putenv

功 能:

把字符串加到当前环境中

用 法:

intputenv(char*envvar);

程序例:

#include

#include

#include

#include

#include

intmain(void)

{

  char*path,*ptr;

  inti=0;

  /*getthecurrentpathenvironment*/

  ptr=getenv("PATH");

  /*setupnewpath*/

  path=malloc(strlen(ptr)+15);

  strcpy(path,"PATH=");

  strcat(path,ptr);

  strcat(path,";c:

\\temp");

  /*replacethecurrentpathanddisplaycurrentenvironment*/

  putenv(path);

  while(environ[i])

      printf("%s\n",environ[i++]);

  return0;

}

 

 

函数名:

putimage

功 能:

在屏幕上输出一个位图

用 法:

voidfarputimage(intx,inty,voidfar*bitmap,intop);

程序例:

#include

#include

#include

#include

#defineARROW_SIZE10

voiddraw_arrow(intx,inty);

intmain(void)

{

  /*requestautodetection*/

  intgdriver=DETECT,gmode,errorcode;

  void*arrow;

  intx,y,maxx;

  unsignedintsize;

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

  x=0;

  y=getmaxy()/2;

  /*drawtheimagetobegrabbed*/

  draw_arrow(x,y);

  /*calculatethesizeoftheimage*/

  size=imagesize(x,y-ARROW_SIZE,x+(4*ARROW_SIZE),y+ARROW_SIZE);

  /*allocatememorytoholdtheimage*/

  arrow=malloc(size);

  /*grabtheimage*/

  getimage(x,y-ARROW_SIZE,x+(4*ARROW_SIZE),y+ARROW_SIZE,arrow);

  /*repeatuntilakeyispressed*/

  while(!

kbhit())

  {

     /*eraseoldimage*/

     putimage(x,y-ARROW_SIZE,arrow,XOR_PUT);

     x+=ARROW_SIZE;

     if(x>=maxx)

    

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

当前位置:首页 > 经管营销 > 人力资源管理

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

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