#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp,*fp_out;
int n;
fp=fopen("dict.txt","r");
if(fp == NULL)
{
perror("fopen error");
exit(1);
}
fp_out = fopen("dict.cp","w");
if(fp_out == NULL)
{
perror("fopen error");
exit(1);
}
while((n = fgetc(fp))!=EOF)
{
fputc(n,fp_out);
}
fclose(fp);
fclose(fp_out);
return 0;
}
~
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#define N 1
int main(int argc,char *argv[])
{
int fd,fd_out;
int n;
char buf[N];
fd = open("dict.txt",O_RDONLY);
if(fd < 0)
{
perror("open dict.txt error");
exit(1);
}
fd_out = open("dict.cp",O_WRONLY|O_CREAT|O_TRUNC,0644);
if(fd_out < 0)
{
perror("open dict.cp error");
exit(1);
}
/*读取dict.txt中的数据
*
*
*
*/
while((n=read(fd,buf,N)))
{
if(n<0)
{
perror("read error");
exit(1);
}
write(fd_out,buf,n);
}
close(fd);
close(fd_out);
return 0;
}
~
即使学了系统调用,不过我们能使用库函数的地方还得使用库函数