linux ,编写一个程序,把一个文件复制到另一个文件上
即实现简单的copy功能
要求:只用 open() read() write() 和close()系统调用.
cat file1 >> file2 ?
open()连个文件,read()其中一个内容,write()到另外一个文件上,最后close()掉。
能不能用lseek函数?
C/C++ code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BUF_SIZE 1024*8
int main()
{
int fds, fdd;
char buf[BUF_SIZE];
size_t hasread = 0;
fds = open("filea", O_RDONLY);
fdd = open("fileb", O_WRONLY, O_CREAT);
if(fds && fdd)
{
while((hasread = read(fds, buf, sizeof(buf))) > 0)
{
write(fdd, buf, hasread);
}
close(fds);
close(fdd);
}
不好意思,少copy半边“}”
非常好
相关问答:
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
一直用svn来做资源的管理,
现在发现windows下取svn 要10个小时左右(资源大约有20G,全是小文件)
linux下取仅用40分钟,
请问linux的文件系统在哪儿比windows文件系统强力?
svn 可够慢的。
在 ......
各位大虾,我正在学习Linux,可是Linux图形界面和命令行之间切换遇到困难,在命令行下输入startx,不是进入图形界面
而是出现
请问各位,这是为什么? 而且按Ctrl+Alt+F7,也不能命令行进入图形界面。
急急急
......
由于我才刚刚接触socket编程,自己写了一个简单程序,但就是在运行的时候出现段错误,无法解决,现在我把源代码贴出来,请各位大虾指正一下!谢谢!
#include<stdio.h>
#include<stdlib.h>
#include& ......
在自己的电脑上安装了ubuntu 就是想玩一下3D桌面,于是下载了
compizconfig-settings-manager
emerald
simple-ccsm
fusion
这些东西,安装完之后,我在电脑里点击了emerald ......