内财数模协会 发表于 2004-5-8 17:08:04

C语言的函数!

**** Hidden Message *****
[此贴子已经被作者于2004-5-10 9:01:54编辑过]

内财数模协会 发表于 2004-5-8 17:08:24

<P>函数名: abs
功能: 求整数的绝对值
用法: int abs(int i);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <P>int main(void)
{
int number = -1234; <P>printf("number: %dabsolute value: %d\n", number, abs(number));
return 0;
}

</P>

内财数模协会 发表于 2004-5-8 17:08:45

<P>函数名: absread, abswirte
功能: 绝对磁盘扇区读、写数据
用法: int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, in tsectno, void *buffer);
程序例:
/* absread example */ <P>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;process.h&gt;
#include &lt;dos.h&gt; <P>int main(void)
{
int i, strt, ch_out, sector;
char buf; <P>printf("Insert a diskette into drive A and press any key\n");
getch();
sector = 0;
if (absread(0, 1, sector, &amp;buf) != 0)
{
   perror("Disk problem");
   exit(1);
}
printf("Read OK\n");
strt = 3;
for (i=0; i&lt;80; i++)
{
   ch_out = buf;
   putchar(ch_out);
}
printf("\n");
return(0);
}


</P>

内财数模协会 发表于 2004-5-8 17:09:12

<P>函数名: access
功能: 确定文件的访问权限
用法: int access(const char *filename, int amode);
程序例:
#include &lt;stdio.h&gt;
#include &lt;io.h&gt; <P>int file_exists(char *filename); <P>int main(void)
{
printf("Does NOTEXIST.FIL exist: %s\n",
file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
return 0;
} <P>int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
</P>

内财数模协会 发表于 2004-5-8 17:09:28

<P>函数名: acos
功能: 反余弦函数
用法: double acos(double x);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <P>int main(void)
{
double result;
double x = 0.5; <P>result = acos(x);
printf("The arc cosine of %lf is %lf\n", x, result);
return 0;
}

</P>

内财数模协会 发表于 2004-5-8 17:10:11

<P>函数名: allocmem
功能: 分配DOS存储段
用法: int allocmem(unsigned size, unsigned *seg);
程序例:
#include &lt;dos.h&gt;
#include &lt;alloc.h&gt;
#include &lt;stdio.h&gt; <P>int main(void)
{
unsigned int size, segp;
int stat; <P>size = 64; /* (64 x 16) = 1024 bytes */
stat = allocmem(size, &amp;segp);
if (stat == -1)
   printf("Allocated memory at segment: %x\n", segp);
else
   printf("Failed: maximum number of paragraphs available is %u\n",
            stat); <P>return 0;
}

</P>

内财数模协会 发表于 2004-5-8 17:10:32

<P>函数名: arc
功能: 画一弧线
用法: void far arc(int x, int y, int stangle, int endangle, int radius);
程序例:
#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <P>int main(void)
{
    /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy;
   int stangle = 45, endangle = 135;
   int radius = 100; <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(); <P>      exit(1);    /* terminate with an error code */
   } <P>   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor()); <P>   /* draw arc */
   arc(midx, midy, stangle, endangle, radius); <P>   /* clean up */
   getch();
   closegraph();
   return 0;
}

</P>

内财数模协会 发表于 2004-5-8 17:10:49

<P>函数名: asctime
功能: 转换日期和时间为ASCII码
用法: char *asctime(const struct tm *tblock);
程序例:
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;time.h&gt; <P>int main(void)
{
   struct tm t;
   char str; <P>   /* sample loading of tm structure*/ <P>   t.tm_sec    = 1;/* Seconds */
   t.tm_min    = 30; /* Minutes */
   t.tm_hour   = 9;/* Hour */
   t.tm_mday   = 22; /* Day of the Month*/
   t.tm_mon    = 11; /* Month */
   t.tm_year   = 56; /* Year - does not include century */
   t.tm_wday   = 4;/* Day of the week*/
   t.tm_yday   = 0;/* Does not show in asctime*/
   t.tm_isdst= 0;/* Is Daylight SavTime; does not show in asctime */ <P>   /* converts structure to null terminated
   string */ <P>   strcpy(str, asctime(&amp;t));
   printf("%s\n", str); <P>   return 0;
}


</P>

内财数模协会 发表于 2004-5-8 17:11:05

<P>函数名: asin
功能: 反正弦函数
用法: double asin(double x);
程序例:
#include &lt;stdio.h&gt;
#include &lt;math.h&gt; <P>int main(void)
{
   double result;
   double x = 0.5; <P>   result = asin(x);
   printf("The arc sin of %lf is %lf\n", x, result);
   return(0);
}


</P>

内财数模协会 发表于 2004-5-8 17:11:20

<P>函数名: assert
功能: 测试一个条件并可能使程序终止
用法: void assert(int test);
程序例:
#include &lt;assert.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt; <P>struct ITEM {
   int key;
   int value;
}; <P>/* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
   assert(itemptr != NULL);
   /* add item to list */
} <P>int main(void)
{
   additem(NULL);
   return 0;
}


</P>
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: C语言的函数!