数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-9 05:36:45 | 显示全部楼层
<>函数名: matherr
功  能: 用户可修改的数学错误处理程序
用  法: int matherr(struct exception *e);
程序例: <>/* This is a user-defined matherr function that prevents
   any error messages from being printed. */ <>#include&lt;math.h&gt; <P>int matherr(struct exception *a)
{
   return 1;
}
  
  
</P>
 楼主| 发表于 2004-5-9 05:37:10 | 显示全部楼层
<>函数名: memccpy
功  能: 从源source中拷贝n个字节到目标destin中
用  法: void *memccpy(void *destin, void *source, unsigned char ch,
       unsigned n);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   char *src = "This is the source string";
   char dest[50];
   char *ptr; <P>   ptr = memccpy(dest, src, 'c', strlen(src)); <P>   if (ptr)
   {
      *ptr = '\0';
      printf("The character was found:  %s\n", dest);
   }
   else
      printf("The character wasn't found\n");
   return 0;
}
</P>
 楼主| 发表于 2004-5-9 05:37:26 | 显示全部楼层
<>函数名: malloc
功  能: 内存分配函数
用  法: void *malloc(unsigned size);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;alloc.h&gt;
#include &lt;process.h&gt; <>int main(void)
{
   char *str; <P>   /* allocate memory for string */
   /* This will generate an error when compiling */
   /* with C++, use the new operator instead. */
   if ((str = malloc(10)) == NULL)
   {
      printf("Not enough memory to allocate buffer\n");
      exit(1);  /* terminate program if out of memory */
   } <P>   /* copy "Hello" into string */
   strcpy(str, "Hello"); <P>   /* display string */
   printf("String is %s\n", str); <P>   /* free memory */
   free(str); <P>   return 0;
}
  
</P>
 楼主| 发表于 2004-5-9 05:37:46 | 显示全部楼层
<>函数名: memchr
功  能: 在数组的前n个字节中搜索字符
用  法: void *memchr(void *s, char ch, unsigned n);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   char str[17];
   char *ptr; <P>   strcpy(str, "This is a string");
   ptr = memchr(str, 'r', strlen(str));
   if (ptr)
      printf("The character 'r' is at position: %d\n", ptr - str);
   else
      printf("The character was not found\n");
   return 0;
}
  </P>
 楼主| 发表于 2004-5-9 05:38:01 | 显示全部楼层
<>函数名: memcpy
功  能: 从源source中拷贝n个字节到目标destin中
用  法: void *memcpy(void *destin, void *source, unsigned n);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(void)
{
   char src[] = "******************************";
   char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
   char *ptr;
   printf("destination before memcpy: %s\n", dest);
   ptr = memcpy(dest, src, strlen(src));
   if (ptr)
      printf("destination after memcpy:  %s\n", dest);
   else
      printf("memcpy failed\n");
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-9 05:38:37 | 显示全部楼层
<>函数名: memicmp
功  能: 比较两个串s1和s2的前n个字节, 忽略大小写
用  法: int memicmp(void *s1, void *s2, unsigned n);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;string.h&gt; <>int main(void)
{
   char *buf1 = "ABCDE123";
   char *buf2 = "abcde456";
   int stat;
   stat = memicmp(buf1, buf2, 5);
   printf("The strings to position 5 are ");
   if (stat)
      printf("not ");
   printf("the same\n");
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-9 05:39:42 | 显示全部楼层
<>函数名: memmove
功  能: 移动一块字节
用  法: void *memmove(void *destin, void *source, unsigned n);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
  char *dest = "abcdefghijklmnopqrstuvwxyz0123456789";
  char *src = "******************************";
  printf("destination prior to memmove: %s\n", dest);
  memmove(dest, src, 26);
  printf("destination after memmove:    %s\n", dest);
  return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-9 05:40:12 | 显示全部楼层
<>函数名: memset
功  能: 设置s中的所有字节为ch, s数组的大小由n给定
用  法: void *memset(void *s, char ch, unsigned n);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;mem.h&gt; <>int main(void)
{
   char buffer[] = "Hello world\n"; <P>   printf("Buffer before memset: %s\n", buffer);
   memset(buffer, '*', strlen(buffer) - 1);
   printf("Buffer after memset:  %s\n", buffer);
   return 0;
}
  
  </P>
 楼主| 发表于 2004-5-9 05:40:39 | 显示全部楼层
<>函数名: mkdir
功  能: 建立一个目录
用  法: int mkdir(char *pathname);
程序例: <>#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;process.h&gt;
#include &lt;dir.h&gt; <>int main(void)
{
  int status; <P>   clrscr();
   status = mkdir("asdfjklm");
   (!status) ? (printf("Directory created\n")) :
               (printf("Unable to create directory\n")); <P>   getch();
   system("dir");
   getch(); <P>   status = rmdir("asdfjklm");
   (!status) ? (printf("Directory deleted\n")) :
  (perror("Unable to delete directory")); <P>   return 0;
}
  
  
  </P>
 楼主| 发表于 2004-5-9 05:41:24 | 显示全部楼层
<>函数名: mktemp
功  能: 建立唯一的文件名
用  法: char *mktemp(char *template);
程序例: <>#include &lt;dir.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   /* fname defines the template for the
     temporary file.  */ <P>   char *fname = "TXXXXXX", *ptr; <P>   ptr = mktemp(fname);
   printf("%s\n",ptr);
   return 0;
}
  
  </P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-11-27 03:58 , Processed in 0.052754 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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