数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:43:07 | 显示全部楼层
<>函数名: getcurdir
功  能: 取指定驱动器的当前目录
用  法: int getcurdir(int drive, char *direc);
程序例: <>#include &lt;dir.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt; <>char *current_directory(char *path)
{
   strcpy(path, "X:\\");      /* fill string with form of response: X:\ */
   path[0] = 'A' + getdisk();    /* replace X with current drive letter */
   getcurdir(0, path+3);  /* fill rest of string with current directory */
   return(path);
} <P>int main(void)
{
   char curdir[MAXPATH]; <P>   current_directory(curdir);
   printf("The current directory is %s\n", curdir); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:43:16 | 显示全部楼层
<>函数名: getcwd
功  能: 取当前工作目录
用  法: char *getcwd(char *buf, int n);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dir.h&gt; <>int main(void)
{
   char buffer[MAXPATH]; <P>   getcwd(buffer, MAXPATH);
   printf("The current directory is: %s\n", buffer);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:43:25 | 显示全部楼层
<>函数名: getdate
功  能: 取DOS日期
用  法: void getdate(struct *dateblk);
程序例: <>#include &lt;dos.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   struct date d; <P>   getdate(&amp;d);
   printf("The current year is: %d\n",
   d.da_year);
   printf("The current day is: %d\n",
   d.da_day);
   printf("The current month is: %d\n",
   d.da_mon);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:43:37 | 显示全部楼层
<>函数名: getdefaultpalette
功  能: 返回调色板定义结构
用  法: struct palettetype *far getdefaultpalette(void);
程序例: <>#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 i; <P>/* structure for returning palette copy */
   struct palettetype far *pal=(void *) 0; <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>   setcolor(getmaxcolor()); <P>/* return a pointer to the default palette */
   pal = getdefaultpalette(); <P>   for (i=0; i&lt;16; i++)
   {
      printf("colors[%d] = %d\n", i,
             pal-&gt;colors);
      getch();
   } <P>/* clean up */
   getch();
   closegraph();
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-8 17:43:46 | 显示全部楼层
<>函数名: getdisk
功  能: 取当前磁盘驱动器号
用  法: int getdisk(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dir.h&gt; <>int main(void)
{
   int disk; <P>   disk = getdisk() + 'A';
   printf("The current drive is: %c\n",
    disk);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:43:58 | 显示全部楼层
<>函数名: getdrivername
功  能: 返回指向包含当前图形驱动程序名字的字符串指针
用  法: char *getdrivename(void);
程序例: <>#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; <P>/* stores the device driver name */
   char *drivername; <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>   setcolor(getmaxcolor()); <P>/* get name of the device driver in use */
   drivername = getdrivername(); <P>/* for centering text on the screen */
   settextjustify(CENTER_TEXT, CENTER_TEXT); <P>/* output the name of the driver */
   outtextxy(getmaxx() / 2, getmaxy() / 2,
      drivername); <P>/* clean up */
   getch();
   closegraph();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:44:08 | 显示全部楼层
<>函数名: getdta
功  能: 取磁盘传输地址
用  法: char far *getdta(void);
程序例: <>#include &lt;dos.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   char far *dta; <P>   dta = getdta();
   printf("The current disk transfer \
   address is: %Fp\n", dta);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:44:19 | 显示全部楼层
<>函数名: getenv
功  能: 从环境中取字符串
用  法: char *getenv(char *envvar);
程序例: <>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
  <>int main(void)
{
    char *s; <P>    s=getenv("COMSPEC");       /* get the comspec environment parameter */
    printf("Command processor: %s\n",s);   /* display comspec parameter */ <P>    return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-8 17:44:32 | 显示全部楼层
<>函数名: getfat, getfatd
功  能: 取文件分配表信息
用  法: void getfat(int drive, struct fatinfo *fatblkp);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>int main(void)
{
   struct fatinfo diskinfo;
   int flag = 0; <P>   printf("Please insert disk in drive A\n");
   getchar(); <P>   getfat(1, &amp;diskinfo);
/* get drive information */ <P>   printf("\nDrive A: is ");
   switch((unsigned char) diskinfo.fi_fatid)
   {
      case 0xFD:
printf("360K low density\n");
break; <P>      case 0xF9:
printf("1.2 Meg high density\n");
break; <P>      default:
printf("unformatted\n");
flag = 1;
   } <P>   if (!flag)
   {
      printf("  sectors per cluster %5d\n",
       diskinfo.fi_sclus);
      printf("   number of clusters %5d\n",
       diskinfo.fi_nclus);
      printf("     bytes per sector %5d\n",
       diskinfo.fi_bysec);
   } <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:44:45 | 显示全部楼层
<>函数名: getfillpattern
功  能: 将用户定义的填充模式拷贝到内存中
用  法: void far getfillpattern(char far *upattern);
程序例: <>#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 maxx, maxy;
   char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; <P>   /* initialize graphics and local variables */
   initgraph(&amp;gdriver, &amp;gmode, ""); <P>   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   } <P>   maxx = getmaxx();
   maxy = getmaxy();
   setcolor(getmaxcolor()); <P>   /* select a user defined fill pattern */
   setfillpattern(pattern, getmaxcolor()); <P>   /* fill the screen with the pattern */
   bar(0, 0, maxx, maxy); <P>   getch(); <P>   /* get the current user defined fill pattern */
   getfillpattern(pattern); <P>   /* alter the pattern we grabbed */
   pattern[4] -= 1;
   pattern[5] -= 3;
   pattern[6] += 3;
   pattern[7] -= 4; <P>   /* select our new pattern */
   setfillpattern(pattern, getmaxcolor()); <P>   /* fill the screen with the new pattern */
   bar(0, 0, maxx, maxy); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}
  
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-4-16 23:10 , Processed in 0.051029 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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