我有一个编程题,谁能帮帮我.

来源:百度知道 编辑:UC知道 时间:2024/06/14 11:57:26
编写一个程序,完成文件的复制功能。源文件名为infile,目标文件名为outfile,源文件名和目标文件均存放在当前目录下。
用C语言编写

请问用什么语言写?c语言?

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 1024

int main(int argc, char **argv)
{
int from_fd, to_fd;
int bytes_read, bytes_write;
char buffer[BUF_SIZE];
char *ptr;

if ( argc != 3 )
{
fprintf(stderr, "Usage: %s fromfile tofile\n\a", argv[0]);
exit(1);
}

/* open source file */
if ( ( from_fd = open(argv[1], O_RDONLY) ) == -1 )
{
fprintf(stderr, "Open %s error : %s\n", argv[1], strerror(errno));
exit(1);
}

/* create target file */
if ( (to_fd = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_