数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:23:13 | 显示全部楼层
<>函数名: cprintf
功  能: 送格式化输出至屏幕
用  法: int cprintf(const char *format[, argument, ...]);
程序例: <>#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 */
   cprintf("Hello world\r\n"); <P>   /* wait for a key */
   getch();
   return 0;
}
</P>
 楼主| 发表于 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>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-3-19 18:10 , Processed in 0.054997 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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