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

C/C++
ActiveX控件中多控制的设计与实现
向CCmdTarget的派生类添加一个接口的实现
多线程安全的变量模板
利用硬件信息实现共享软件的安全注册
托管C++程序开发—Win表单文档程序设计(下)
在ATL中实现窗口
基于Visual C++ 的自动化客户端的实现
ATL接口映射宏详解
托管C++程序开发—Win表单文档程序设计(中)
使用Visual C++开发SOAP客户端应用
Visual C#的SQL Server编程
VC# .Net中浏览Crystal Report
关于GC:Dotnet中Dispose的设计模式
Visual C++ 优化概述
Visual C++.NET GDI+编程基础
.NET 中的断言和跟踪
每个开发人员现在应该下载的十种必备工具
代码最优化.NET中的内存管理
在VC++下对文件属性的获取与更改
高手必看:C、C++程序的优化之路

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 168 ::
收藏到网摘: 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;

}

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