数模论坛

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

C语言的函数!

  [复制链接]
 楼主| 发表于 2004-5-8 17:37:18 | 显示全部楼层
<>函数名: fnmerge
功  能: 建立新文件名
用  法: void fnerge(char *path, char *drive, char *dir);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;dir.h&gt;
  <>int main(void)
{
    char s[MAXPATH];
    char drive[MAXDRIVE];
    char dir[MAXDIR];
    char file[MAXFILE];
    char ext[MAXEXT]; <P>    getcwd(s,MAXPATH);              /* get the current working directory */
    strcat(s,"\\");                  /* append on a trailing \ character */
    fnsplit(s,drive,dir,file,ext); /* split the string to separate elems */
    strcpy(file,"DATA");
    strcpy(ext,".TXT");
    fnmerge(s,drive,dir,file,ext);   /* merge everything into one string */
    puts(s);                                 /* display resulting string */ <P>    return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-8 17:37:29 | 显示全部楼层
<>函数名: fopen
功  能: 打开一个流
用  法: FILE *fopen(char *filename, char *type);
程序例: <>#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;dir.h&gt; <>int main(void)
{
    char *s;
    char drive[MAXDRIVE];
    char dir[MAXDIR];
    char file[MAXFILE];
    char ext[MAXEXT];
    int flags; <P>    s=getenv("COMSPEC"); /* get the comspec environment parameter */
    flags=fnsplit(s,drive,dir,file,ext); <P>    printf("Command processor inf\n");
    if(flags &amp; DRIVE)
       printf("\tdrive: %s\n",drive);
    if(flags &amp; DIRECTORY)
       printf("\tdirectory: %s\n",dir);
    if(flags &amp; FILENAME)
       printf("\tfile: %s\n",file);
    if(flags &amp; EXTENSION)
       printf("\textension: %s\n",ext); <P>    return 0;
}
  </P>
 楼主| 发表于 2004-5-8 17:37:40 | 显示全部楼层
<>函数名: fprintf
功  能: 传送格式化输出到一个流中
用  法: int fprintf(FILE *stream, char *format[, argument,...]);
程序例: <>/* Program to create backup of the
   AUTOEXEC.BAT file */ <>#include &lt;stdio.h&gt; <P>int main(void)
{
   FILE *in, *out; <P>   if ((in = fopen("\\AUTOEXEC.BAT", "rt"))
       == NULL)
   {
      fprintf(stderr, "Cannot open input \
       file.\n");
      return 1;
   } <P>   if ((out = fopen("\\AUTOEXEC.BAK", "wt"))
       == NULL)
   {
      fprintf(stderr, "Cannot open output \
       file.\n");
      return 1;
   } <P>   while (!feof(in))
      fputc(fgetc(in), out); <P>   fclose(in);
   fclose(out);
   return 0;
}
  
  
</P>
 楼主| 发表于 2004-5-8 17:37:48 | 显示全部楼层
<>函数名: FP_OFF
功  能: 获取远地址偏移量
用  法: unsigned FP_OFF(void far *farptr);
程序例: <>/* FP_OFF */ <>#include &lt;dos.h&gt;
#include &lt;stdio.h&gt; <P>int main(void)
{
   char *str = "fpoff.c"; <P>   printf("The offset of this file in memory\
          is: %Fp\n", FP_OFF(str)); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:37:56 | 显示全部楼层
<>函数名: FP_SEG
功  能: 获取远地址段值
用  法: unsigned FP_SEG(void far *farptr);
程序例: <>/* FP_SEG */ <>#include &lt;dos.h&gt;
#include &lt;stdio.h&gt; <P>int main(void)
{
   char *filename = "fpseg.c"; <P>   printf("The offset of this file in memory\
   is: %Fp\n", FP_SEG(filename)); <P>   return(0);
}
</P>
 楼主| 发表于 2004-5-8 17:38:05 | 显示全部楼层
<>函数名: fputc
功  能: 送一个字符到一个流中
用  法: int fputc(int ch, FILE *stream);
程序例: <>#include &lt;stdio.h&gt; <>int main(void)
{
   char msg[] = "Hello world";
   int i = 0; <P>   while (msg)
   {
      fputc(msg, stdout);
      i++;
   }
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:38:15 | 显示全部楼层
<>函数名: fputchar
功  能: 送一个字符到标准输出流(stdout)中
用  法: int fputchar(char ch);
程序例: <>#include &lt;stdio.h&gt; <>int main(void)
{
   char msg[] = "This is a test";
   int i = 0; <P>   while (msg)
   {
      fputchar(msg);
      i++;
   }
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:38:24 | 显示全部楼层
<>函数名: fputs
功  能: 送一个字符到一个流中
用  法: int fputs(char *string, FILE *stream);
程序例: <>#include &lt;stdio.h&gt; <>int main(void)
{
   /* write a string to standard output */
   fputs("Hello world\n", stdout); <P>   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:38:33 | 显示全部楼层
<>函数名: fread
功  能: 从一个流中读数据
用  法: int fread(void *ptr, int size, int nitems, FILE *stream);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt; <>int main(void)
{
   FILE *stream;
   char msg[] = "this is a test";
   char buf[20]; <P>   if ((stream = fopen("DUMMY.FIL", "w+"))
       == NULL)
   {
      fprintf(stderr,
              "Cannot open output file.\n");
      return 1;
   } <P>   /* write some data to the file */
   fwrite(msg, strlen(msg)+1, 1, stream); <P>   /* seek to the beginning of the file */
   fseek(stream, SEEK_SET, 0); <P>   /* read the data and display it */
   fread(buf, strlen(msg)+1, 1, stream);
   printf("%s\n", buf); <P>   fclose(stream);
   return 0;
}
</P>
 楼主| 发表于 2004-5-8 17:38:44 | 显示全部楼层
<>函数名: free
功  能: 释放已分配的块
用  法: void free(void *ptr);
程序例: <>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
#include &lt;alloc.h&gt; <>int main(void)
{
   char *str; <P>   /* allocate memory for string */
   str = malloc(10); <P>   /* copy "Hello" to string */
   strcpy(str, "Hello"); <P>   /* display string */
   printf("String is %s\n", str); <P>   /* free memory */
   free(str); <P>   return 0;
}
  </P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

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

GMT+8, 2024-3-29 08:54 , Processed in 0.050307 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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