c语言函数--D

函数名: delay

功 能: 将程序的执行暂停一段时间(毫秒)

用 法: void delay(unsigned milliseconds);

程序例:

/* Emits a 440-Hz tone for 500 milliseconds */
#include <dos.h>
int main(void)
{
   sound(440);
   delay(500);
   nosound();
   return 0;
}

函数名: delline

功 能: 在文本窗口中删去一行

用 法: void delline(void);

程序例:

#include <conio.h>
int main(void)
{
   clrscr();
   cprintf("The function DELLINE deletes \
    the line containing the\r\n");
   cprintf("cursor and moves all lines \
    below it one line up.\r\n");
   cprintf("DELLINE operates within the \
    currently active text\r\n");
   cprintf("window.  Press any key to \
    continue . . .");
   gotoxy(1,2);  /* Move the cursor to the
      second line and first column */
   getch();
   delline();
   getch();
   return 0;
}

函数名: detectgraph

功 能: 通过检测硬件确定图形驱动程序和模式

用 法: void far detectgraph(int far *graphdriver, int far *graphmode);

程序例:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
/* names of the various cards supported */
char *dname[] = { "requests detection",
    "a CGA",
    "an MCGA",
    "an EGA",
    "a 64K EGA",
    "a monochrome EGA",
    "an IBM 8514",
    "a Hercules monochrome",
    "an AT&T 6300 PC",
    "a VGA",
    "an IBM 3270 PC"
  };
int main(void)
{
   /* returns detected hardware info. */
   int gdriver, gmode, errorcode;
  /* detect graphics hardware available */
   detectgraph(&gdriver, &gmode);
   /* read result of detectgraph call */
   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 */
   }
   /* display the information detected */
   clrscr();
   printf("You have %s video display \
   card.\n", dname[gdriver]);
   printf("Press any key to halt:");
   getch();
   return 0;
}

函数名: difftime

功 能: 计算两个时刻之间的时间差

用 法: double difftime(time_t time2, time_t time1);

程序例:

#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
int main(void)
{
   time_t first, second;
   clrscr();
   first = time(NULL);  /* Gets system
      time */
   delay(2000);         /* Waits 2 secs */
   second = time(NULL); /* Gets system time
      again */
   printf("The difference is: %f \
   seconds\n",difftime(second,first));
   getch();
   return 0;
}

函数名: disable

功 能: 屏蔽中断

用 法: void disable(void);

程序例:

/***NOTE: This is an interrupt service
 routine. You cannot compile this program
 with Test Stack Overflow turned on and
 get an executable file that operates
 correctly. */
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C    /* The clock tick
   interrupt */
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
/* disable interrupts during the handling of
   the interrupt */
   disable();
/* increase the global counter */
   count++;
/* reenable interrupts at the end of the
   handler */
   enable();
/* call the old routine */
   oldhandler();
}
int main(void)
{
/* save the old interrupt vector */
   oldhandler = getvect(INTR);
/* install the new interrupt handler */
   setvect(INTR, handler);
/* loop until the counter exceeds 20 */
   while (count < 20)
      printf("count is %d\n",count);
/* reset the old interrupt handler */
   setvect(INTR, oldhandler);
   return 0;
}

函数名: div

功 能: 将两个整数相除, 返回商和余数

用 法: div_t (int number, int denom);

程序例:

#include <stdlib.h>
#include <stdio.h>
div_t x;
int main(void)
{
   x = div(10,3);
   printf("10 div 3 = %d remainder %d\n", x.quot, x.rem);
   return 0;
}

函数名: dosexterr

功 能: 获取扩展DOS错误信息

用 法: int dosexterr(struct DOSERR *dblkp);

程序例:

#include <stdio.h>
#include <dos.h>
int main(void)
{
   FILE *fp;
   struct DOSERROR info;
   fp = fopen("perror.dat","r");
   if (!fp) perror("Unable to open file for
     reading");
   dosexterr(&info);
   printf("Extended DOS error \
   information:\n");
   printf("   Extended error: \
   %d\n",info.exterror);
   printf("            Class: \
   %x\n",info.class);
   printf("           Action: \
   %x\n",info.action);
   printf("      Error Locus: \
   %x\n",info.locus);
   return 0;
}

函数名: dostounix

功 能: 转换日期和时间为UNIX时间格式

用 法: long dostounix(struct date *dateptr, struct time *timeptr);

程序例:

 #include <time.h>
 #include <stddef.h>
 #include <dos.h>
 #include <stdio.h>
 int main(void)
 {
    time_t t;
    struct time d_time;
    struct date d_date;
    struct tm *local;
    getdate(&d_date);
    gettime(&d_time);
    t = dostounix(&d_date, &d_time);
    local = localtime(&t);
    printf("Time and Date: %s\n", \
    asctime(local));
    return 0;
}

函数名: drawpoly

功 能: 画多边形

用 法: void far drawpoly(int numpoints, int far *polypoints);

程序例:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int maxx, maxy;
   /* our polygon array */
   int poly[10];
   /* initialize graphics and local
      variables */
   initgraph(&gdriver, &gmode, "");
   /* 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();
   /* terminate with an error code */
      exit(1);
   }
   maxx = getmaxx();
   maxy = getmaxy();
   poly[0] = 20;        /* 1st vertext */
   poly[1] = maxy / 2;
   poly[2] = maxx - 20; /* 2nd */
   poly[3] = 20;
   poly[4] = maxx - 50; /* 3rd */
   poly[5] = maxy - 20;
   poly[6] = maxx / 2;  /* 4th */
   poly[7] = maxy / 2;
/*
   drawpoly doesn‘t automatically close
   the polygon, so we close it.
*/
   poly[8] = poly[0];
   poly[9] = poly[1];
   /* draw the polygon */
   drawpoly(5, poly);
   /* clean up */
   getch();
   closegraph();
   return 0;
}

函数名: dup

功 能: 复制一个文件句柄

用 法: int dup(int handle);

程序例:

#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <io.h>
void flush(FILE *stream);
int main(void)
{
   FILE *fp;
   char msg[] = "This is a test";
   /* create a file */
   fp = fopen("DUMMY.FIL", "w");
   /* write some data to the file */
   fwrite(msg, strlen(msg), 1, fp);
   clrscr();
   printf("Press any key to flush \
   DUMMY.FIL:");
   getch();
   /* flush the data to DUMMY.FIL without
      closing it */
   flush(fp);
   printf("\nFile was flushed, Press any \
   key to quit:");
   getch();
   return 0;
}
void flush(FILE *stream)
{
   int duphandle;
   /* flush TC‘s internal buffer */
   fflush(stream);
   /* make a duplicate file handle */
   duphandle = dup(fileno(stream));
   /* close the duplicate handle to flush the
      DOS buffer */
   close(duphandle);
}

函数名: dup2

功 能: 复制文件句柄

用 法: int dup2(int oldhandle, int newhandle);

程序例:

#include <sys\stat.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
int main(void)
{
   #define STDOUT 1
   int nul, oldstdout;
   char msg[] = "This is a test";
   /* create a file */
   nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
      S_IREAD | S_IWRITE);
   /* create a duplicate handle for standard
      output */
   oldstdout = dup(STDOUT);
   /*
      redirect standard output to DUMMY.FIL
      by duplicating the file handle onto the
      file handle for standard output.
   */
   dup2(nul, STDOUT);
   /* close the handle for DUMMY.FIL */
   close(nul);
   /* will be redirected into DUMMY.FIL */
   write(STDOUT, msg, strlen(msg));
   /* restore original standard output
      handle */
   dup2(oldstdout, STDOUT);
   /* close duplicate handle for STDOUT */
   close(oldstdout);
   return 0;
}

书画小说软件 制作更惬意的读、更舒心的写、更轻松的发布

时间: 2025-01-14 10:53:03

c语言函数--D的相关文章

C#委托与C语言函数指针及函数指针数组

C#委托与C语言函数指针及函数指针数组 在使用C#时总会为委托而感到疑惑,但现在总新温习了一遍C语言后,才真正理解的委托. 其实委托就类似于C/C++里的函数指针,在函数传参时传递的是函数指针,在调用的时候通过指针访问这个函数. 在C语言中函数指针的申明如下: //可以理解为申明一个指着变量 Func ,它的类型是 返回Type(可以为 void )类型的参数,接收 (Type one,Type two,...)类型的//参数(可以不接受参数). Type *Func(Type one,Type

c 语言 函数的整理 百度脑图版本

下面整理一下C语言函数的知识点 :使用百度脑图进行整理,详情请看上传的图片: 版权声明:本文为博主原创文章,未经博主允许不得转载.

汇编1 ----C语言函数1

构造以下C程序并在合适位置插入breakpoints 在Visual Studio 2015 CTP6对其反汇编. 下面来分析 z = add(1, 2); 009C170E 6A 02 push 2 ????int z; ????z = add(1, 2); 009C1710 6A 01 push 1 009C1712 E8 8D FA FF FF call 009C11A4 009C1717 83 C4 08 add esp,8 009C171A 89 45 F8 mov dword ptr

(转)如何编写有多个返回值的C语言函数

1引言    笔者从事C语言教学多年,在教学中学生们常常会问到如何编写具有多个返回值的C语言函数.编写有多个返回值的函数是所有C语言教材里均没有提到的知识点,但在实际教学与应用的过程中我们都有可能会遇到这样的问题.有学生也尝试了不少方法:如把多个需要返回的值作相应的处理后变成一个可以用return语句返回的数据,再在主调函数中拆开返回的数据使之变成几个值:或者把需要返回多个值的一个函数分开几个函数去实现多个值的返回.这些方法虽然最终都能实现返回要求的多个值,但从程序算法的合理性与最优化方面去考虑

Linux汇编GAS调用C语言函数实例

Blum的书上只讲了C语言调用汇编,没讲汇编调用C语言.我自己尝试了下. 最终试验成功了,在此写出与大家分享.期间历经无数错误,无数异常,我不是醉了,而是跪了...好在最后好了. 程序实现一个换值功能,在main.s里定义a=10,b=20,然后调用C语言函数把a,b换值. 新建两个文件分别为main.s的汇编文件,还有pro.c的C语言函数文件. main.s的代码如下: .section .data a: .int 10 b: .int 20 .section .text .globl ma

C语言函数sscanf()的用法 (转载

在我的学习过程中,从文件读取数据是一件很麻烦的事,所幸有sscanf()函数. C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var1, mixed var2 ... ); int scanf( const char *format [,argument]... ); 说明: sscanf与scanf类似,都是用于输入的,只是后者以屏幕(stdin)

C语言函数sscanf()的用法(转)

转自:http://www.cnblogs.com/lyq105/archive/2009/11/28/1612677.html C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var1, mixed var2 ... ); int scanf( const char *format [,argument]... ); 说明: sscanf与scanf

[整理]C语言函数说明和定义

函数的一般形式是:type-specifier function_name(parameter list) parameter declarations{   body of the function} 1.类型说明符定义了函数中return语句返回值的类型,该返回值可以是任何有效类型.假如没有类型说明符出现,函数返回一个整型值. 当一个函数没有明确说明类型时, C语言的编译程序自动将整型( i n t)作为这个函数的缺省类型,缺省类型适用于很大一部分函数. 当有必要返回其它类型数据时,需要分两

从linux0.11中起动部分代码看汇编调用c语言函数

上一篇分析了c语言的函数调用栈情况,知道了c语言的函数调用机制后,我们来看一下,linux0.11中起动部分的代码是如何从汇编跳入c语言函数的.在LINUX 0.11中的head.s文件中会看到如下一段代码(linux0.11的启动分析部分会在另一部分中再分析,由于此文仅涉及c与汇编代码的问题,). after_page_tables: pushl $0 # These are the parameters to main :-) pushl $0 pushl $0 pushl $L6 # re

借助动态代码生成技术在基于Webkit引擎的HTML5网页JS内调用易语言函数

作者:庄晓立(Liigo) 日期:2015年3月3日夜 原创链接:http://blog.csdn.net/liigo/article/details/44045177 版权所有,转载请注明出处:http://blog.csdn.net/liigo 前两天我协助解决了一个技术问题,在此稍作记录和总结. 具体来说,就是在使用基于Webkit引擎的封装组件wke的过程中,需要把一个易语言函数注册给JavaScript引擎,让它可以在网页里被调用(就像在网页里调用普通JavaScript函数一样).如