数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:41:15 | 显示全部楼层
<>函数名: geninterrupt
功  能: 产生一个软中断
用  法: void geninterrupt(int intr_num);
程序例: <>#include &lt;conio.h&gt;
#include &lt;dos.h&gt; <>/* function prototype */
void writechar(char ch); <P>int main(void)
{
   clrscr();
   gotoxy(80,25);
   writechar('*');
   getch();
   return 0;
} <P>/*
   outputs a character at the current cursor
   position using the video BIOS to avoid the
   scrolling of the screen when writing to
   location (80,25).
*/ <P>void writechar(char ch)
{
   struct text_info ti;
   /* grab current text settings */
   gettextinfo(&amp;ti);
   /* interrupt 0x10 sub-function 9 */
   _AH = 9;
   /* character to be output */
   _AL = ch;
   _BH = 0;                  /* video page */
   _BL = ti.attribute;  /* video attribute */
   _CX = 1;           /* repetition factor */
   geninterrupt(0x10);  /* output the char */
}
  
  </P>
 楼主| 发表于 2004-5-8 17:41:27 | 显示全部楼层
<>函数名: getarccoords
功  能: 取得最后一次调用arc的坐标
用  法: void far getarccoords(struct arccoordstype far *arccoords);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
/* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   struct arccoordstype arcinfo;
   int midx, midy;
   int stangle = 45, endangle = 270;
   char sstr[80], estr[80]; <P>/* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>/* read result of initialization */
   errorcode = graphresult();
/* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n",
             grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
/* terminate with an error code */
      exit(1);
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2; <P>/* draw arc and get coordinates */
   setcolor(getmaxcolor());
   arc(midx, midy, stangle, endangle, 100);
   getarccoords(&amp;arcinfo); <P>/* convert arc information into strings */
   sprintf(sstr, "*- (%d, %d)",
           arcinfo.xstart, arcinfo.ystart);
   sprintf(estr, "*- (%d, %d)",
           arcinfo.xend, arcinfo.yend); <P>   /* output the arc information */
   outtextxy(arcinfo.xstart,
             arcinfo.ystart, sstr);
   outtextxy(arcinfo.xend,
             arcinfo.yend, estr); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-8 17:41:39 | 显示全部楼层
<>函数名: getaspectratio
功  能: 返回当前图形模式的纵横比
用  法: void far getaspectratio(int far *xasp, int far *yasp);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
/* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int xasp, yasp, midx, midy; <P>/* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>/* read result of initialization */
   errorcode = graphresult();
/* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n",
             grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
/* terminate with an error code */
      exit(1);
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor()); <P>/* get current aspect ratio settings */
   getaspectratio(&amp;xasp, &amp;yasp); <P>/* draw normal circle */
   circle(midx, midy, 100);
   getch(); <P>/* draw wide circle */
   cleardevice();
   setaspectratio(xasp/2, yasp);
   circle(midx, midy, 100);
   getch(); <P>/* draw narrow circle */
   cleardevice();
   setaspectratio(xasp, yasp/2);
   circle(midx, midy, 100); <P>/* clean up */
   getch();
   closegraph();
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-8 17:41:50 | 显示全部楼层
<>函数名: getbkcolor
功  能: 返回当前背景颜色
用  法: int far getbkcolor(void);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int bkcolor, midx, midy;
   char bkname[35]; <P>/* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>/* read result of initialization */
   errorcode = graphresult();
/* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n",
             grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
/* terminate with an error code */
      exit(1);
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor()); <P>/* for centering text on the display */
   settextjustify(CENTER_TEXT, CENTER_TEXT); <P>/* get the current background color */
   bkcolor = getbkcolor(); <P>/* convert color value into a string */
   itoa(bkcolor, bkname, 10);
   strcat(bkname,
" is the current background color."); <P>/* display a message */
   outtextxy(midx, midy, bkname); <P>/* clean up */
   getch();
   closegraph();
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:41:59 | 显示全部楼层
<>函数名: getc
功  能: 从流中取字符
用  法: int getc(FILE *stream);
程序例: <>#include &lt;stdio.h&gt; <>int main(void)
{
   char ch; <P>   printf("Input a character:");
/* read a character from the
   standard input stream */
   ch = getc(stdin);
   printf("The character input was: '%c'\n",
          ch);
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:42:08 | 显示全部楼层
<>函数名: getcbrk
功  能: 获取Control_break设置
用  法: int getcbrk(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   if (getcbrk())
      printf("Cntrl-brk flag is on\n");
   else
      printf("Cntrl-brk flag is off\n"); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:42:20 | 显示全部楼层
<>函数名: getch
功  能: 从控制台无回显地取一个字符
用  法: int getch(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   char ch; <P>   printf("Input a character:");
   ch = getche();
   printf("\nYou input a '%c'\n", ch);
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:42:29 | 显示全部楼层
<>函数名: getchar
功  能: 从stdin流中读字符
用  法: int getchar(void);
程序例: <>#include &lt;stdio.h&gt; <>int main(void)
{
   int c; <P>   /* Note that getchar reads from stdin and
      is line buffered; this means it will
      not return until you press ENTER. */ <P>   while ((c = getchar()) != '\n')
      printf("%c", c); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:42:39 | 显示全部楼层
<>函数名: getche
功  能: 从控制台取字符(带回显)
用  法: int getche(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
   char ch; <P>   printf("Input a character:");
   ch = getche();
   printf("\nYou input a '%c'\n", ch);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:42:50 | 显示全部楼层
<>函数名: getcolor
功  能: 返回当前画线颜色
用  法: int far getcolor(void);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>int main(void)
{
/* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int color, midx, midy;
   char colname[35]; <P>/* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>/* read result of initialization */
   errorcode = graphresult();
/* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n",
             grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
/* terminate with an error code */
      exit(1);
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor()); <P>/* for centering text on the display */
   settextjustify(CENTER_TEXT, CENTER_TEXT); <P>/* get the current drawing color */
   color = getcolor(); <P>/* convert color value into a string */
   itoa(color, colname, 10);
   strcat(colname,
   " is the current drawing color."); <P>/* display a message */
   outtextxy(midx, midy, colname); <P>/* clean up */
   getch();
   closegraph();
   return 0;
}
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-4-19 21:44 , Processed in 0.048039 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表