当前位置: 首页 > 图文教程 > 开发语言 > C/C++ > C/C++:小编谈C语言函数那些事(1)

C/C++
任意分布的随机数的产生方法—VC程序实现方法
用Visual C++实现PDF文件的显示
利用Visual C#打造一个平滑的进度条
C/C++ 程序设计员应聘常见面试试题深入剖析
什么是sdk?

C/C++:小编谈C语言函数那些事(1)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 165 ::
收藏到网摘: n/a

好久没有更新C语言的文章了,因为小编最近没有研究C语言,所以嘛也没什么灵感,今天跟朋友讨论了几个C语言的函数问题,就想到要总结一篇这样的文章,希望对大家有所帮助吧。言归正传,以下是为大家总结的C语言函数的使用方法。

1.Allocmem函数

Allocmem函数是分配DOS存储段,其用法为:int allocmem(unsigned size, unsigned *seg);

为了让大家更能明白他的准确用法下面举个程序例子:

#include <dos.h>

#include <alloc.h>

#include <stdio.h>

int main(void)

{

  unsigned int size, segp;

  int stat;

  size = 64; /* (64 x 16) = 1024 bytes */

  stat = allocmem(size, &segp);

  if (stat == -1)

     printf("Allocated memory at segment: %x\n", segp);

  else

     printf("Failed: maximum number of paragraphs available is %u\n",

            stat);

  return 0;

}

2. asctime函数

Asctime函数是转换日期和时间为ASCII码,其用法为:char *asctime(const struct tm *tblock); 程序例子如下:

#include <stdio.h>

#include <string.h>

#include <time.h>

int main(void)

{

   struct tm t;

   char str[80];

   /* sample loading of tm structure  */

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

   /* converts structure to null terminated

   string */

   strcpy(str, asctime(&t));

   printf("%s\n", str);

   return 0;

}

3. atof函数

Atof函数是把字符串转换成浮点数,其用法为:double atof(const char *nptr);,程序例子如下:

#include <stdlib.h>

#include <stdio.h>

int main(void)

{

   float f;

   char *str = "12345.67";

   f = atof(str);

   printf("string = %s float = %f\n", str, f);

   return 0;

}

由于篇幅有限,小编就先和大家分享这几个函数,以后小编会不断推出类似的文章跟大家分享。