设为首页 加入收藏

TOP

C语言函数集(五)(六)
2014-11-23 21:42:03 来源: 作者: 【 】 浏览:34
Tags:语言 函数
parameter */
flags=fnsplit(s,drive,dir,file,ext);
printf("Command processor info:\n");
if(flags & DRIVE)
printf("\tdrive: %s\n",drive);
if(flags & DIRECTORY)
printf("\tdirectory: %s\n",dir);
if(flags & FILENAME)
printf("\tfile: %s\n",file);
if(flags & EXTENSION)
printf("\textension: %s\n",ext);
return 0;
}
函数名: fprintf
功 能: 传送格式化输出到一个流中
用 法: int fprintf(FILE *stream, char *format[, argument,...]);
程序例:
/* Program to create backup of the
AUTOEXEC.BAT file */
#include
int main(void)
{
FILE *in, *out;
if ((in = fopen("\\AUTOEXEC.BAT", "rt"))
== NULL)
{
fprintf(stderr, "Cannot open input \
file.\n");
return 1;
}
if ((out = fopen("\\AUTOEXEC.BAK", "wt"))
== NULL)
{
fprintf(stderr, "Cannot open output \
file.\n");
return 1;
}
while (!feof(in))
fputc(fgetc(in), out);
fclose(in);
fclose(out);
return 0;
}
函数名: FP_OFF
功 能: 获取远地址偏移量
用 法: unsigned FP_OFF(void far *farptr);
程序例:
/* FP_OFF */
#include
#include
int main(void)
{
char *str = "fpoff.c";
printf("The offset of this file in memory\
is: %Fp\n", FP_OFF(str));
return 0;
}
函数名: FP_SEG
功 能: 获取远地址段值
用 法: unsigned FP_SEG(void far *farptr);
程序例:
/* FP_SEG */
#include
#include
int main(void)
{
char *filename = "fpseg.c";
printf("The offset of this file in memory\
is: %Fp\n", FP_SEG(filename));
return(0);
}
函数名: fputc
功 能: 送一个字符到一个流中
用 法: int fputc(int ch, FILE *stream);
程序例:
#include
int main(void)
{
char msg[] = "Hello world";
int i = 0;
while (msg[i])
{
fputc(msg[i], stdout);
i++;
}
return 0;
}
函数名: fputchar
功 能: 送一个字符到标准输出流(stdout)中
用 法: int fputchar(char ch);
程序例:
#include
int main(void)
{
char msg[] = "This is a test";
int i = 0;
while (msg[i])
{
fputchar(msg[i]);
i++;
}
return 0;
}
函数名: fputs
功 能: 送一个字符到一个流中
用 法: int fputs(char *string, FILE *stream);
程序例:
#include
int main(void)
{
/* write a string to standard output */
fputs("Hello world\n", stdout);
return 0;
}
函数名: fread
功 能: 从一个流中读数据
用 法: int fread(void *ptr, int size, int nitems, FILE *stream);
程序例:
#include
#include
int main(void)
{
FILE *stream;
char msg[] = "this is a test";
char buf[20];
if ((stream = fopen("DUMMY.FIL", "w+"))
== NULL)
{
fprintf(stderr,
"Cannot open output file.\n");
return 1;
}
/* write some data to the file */
fwrite(msg, strlen(msg)+1, 1, stream);
/* seek to the beginning of the file */
fseek(stream, SEEK_SET, 0);
/* read the data and display it */
fread(buf, strlen(msg)+1, 1, stream);
printf("%s\n", buf);
fclose(stream);
return 0;
}
函数名: free
功 能: 释放已分配的块
用 法: void free(void *ptr);
程序例:
#include
#include
#
首页 上一页 3 4 5 6 7 8 下一页 尾页 6/8/8
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言函数集(六) 下一篇C语言函数集(四)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: