数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:23:20 | 显示全部楼层
<>函数名: cputs
功  能: 写字符到屏幕
用  法: void cputs(const char *string);
程序例: <>#include &lt;conio.h&gt; <>int main(void)
{
   /* clear the screen */
   clrscr(); <P>   /* create a text window */
   window(10, 10, 80, 25); <P>   /* output some text in the window */
   cputs("This is within the window\r\n"); <P>   /* wait for a key */
   getch();
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:23:29 | 显示全部楼层
<>函数名: _creat  creat
功  能: 创建一个新文件或重写一个已存在的文件
用  法: int creat (const char *filename, int permiss);
程序例: <>#include &lt;sys\stat.h&gt;
#include &lt;string.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   int handle;
   char buf[11] = "0123456789"; <P>   /* change the default file mode from text to binary */
   _fmode = O_BINARY; <P>   /* create a binary file for reading and writing */
   handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE); <P>   /* write 10 bytes to the file */
   write(handle, buf, strlen(buf)); <P>   /* close the file */
   close(handle);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:23:37 | 显示全部楼层
<>函数名: creatnew
功  能: 创建一个新文件
用  法: int creatnew(const char *filename, int attrib);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;errno.h&gt;
#include &lt;dos.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   int handle;
   char buf[11] = "0123456789"; <P>   /* attempt to create a file that doesn't already exist */
   handle = creatnew("DUMMY.FIL", 0); <P>   if (handle == -1)
      printf("DUMMY.FIL already exists.\n");
   else
   {
      printf("DUMMY.FIL successfully created.\n");
      write(handle, buf, strlen(buf));
      close(handle);
   }
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:23:47 | 显示全部楼层
<>函数名: creattemp
功  能: 创建一个新文件或重写一个已存在的文件
用  法: int creattemp(const char *filename, int attrib);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;io.h&gt; <>int main(void)
{
   int handle;
   char pathname[128]; <P>   strcpy(pathname, "\\"); <P>   /* create a unique file in the root directory */
   handle = creattemp(pathname, 0); <P>   printf("%s was the unique file created.\n", pathname);
   close(handle);
   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-8 17:23:58 | 显示全部楼层
<>函数名: cscanf
功  能: 从控制台执行格式化输入
用  法: int cscanf(char *format[,argument, ...]);
程序例: <>#include &lt;conio.h&gt; <>int main(void)
{
   char string[80]; <P>   /* clear the screen */
   clrscr(); <P>   /* Prompt the user for input */
   cprintf("Enter a string with no spaces:"); <P>   /* read the input */
   cscanf("%s", string); <P>   /* display what was read */
   cprintf("\r\nThe string entered is: %s", string);
   return 0;
}
  
  

</P>
 楼主| 发表于 2004-5-8 17:24:10 | 显示全部楼层
<>函数名: ctime
功  能: 把日期和时间转换为字符串
用  法: char *ctime(const time_t *time);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;time.h&gt; <>int main(void)
{
   time_t t; <P>   time(&amp;t);
   printf("Today's date and time: %s\n", ctime(&amp;t));
   return 0;
}
  
</P>
 楼主| 发表于 2004-5-8 17:24:21 | 显示全部楼层
<>函数名: ctrlbrk
功  能: 设置Ctrl-Break处理程序
用  法: void ctrlbrk(*fptr)(void);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;dos.h&gt; <>#define ABORT 0 <P>int c_break(void)
{
   printf("Control-Break pressed.  Program aborting ...\n");
   return (ABORT);
} <P>int main(void)
{
   ctrlbrk(c_break);
   for(;;)
   {
      printf("Looping... Press &lt;Ctrl-Break&gt; to quit:\n");
   }
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:25:01 | 显示全部楼层
<>函数名: delay
功  能: 将程序的执行暂停一段时间(毫秒)
用  法: void delay(unsigned milliseconds);
程序例:
/* Emits a 440-Hz tone for 500 milliseconds */
#include &lt;dos.h&gt; <>int main(void)
{
   sound(440);
   delay(500);
   nosound(); <>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:25:19 | 显示全部楼层
<>函数名: delline
功  能: 在文本窗口中删去一行
用  法: void delline(void);
程序例: <>#include &lt;conio.h&gt; <>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(); <P>   delline();
   getch(); <P>   return 0;
}
  </P>
 楼主| 发表于 2004-5-8 17:25:31 | 显示全部楼层
<>函数名: detectgraph
功  能: 通过检测硬件确定图形驱动程序和模式
用  法: void far detectgraph(int far *graphdriver, int far *graphmode);
程序例: <>#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt; <>/* 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&amp;T 6300 PC",
    "a VGA",
    "an IBM 3270 PC"
  }; <P>int main(void)
{
   /* returns detected hardware info. */
   int gdriver, gmode, errorcode; <P>  /* detect graphics hardware available */
   detectgraph(&amp;gdriver, &amp;gmode); <P>   /* 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 */
   } <P>   /* display the information detected */
   clrscr();
   printf("You have %s video display \
   card.\n", dname[gdriver]);
   printf("Press any key to halt:");
   getch();
   return 0;
}
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-11-26 20:48 , Processed in 0.104895 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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