#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
int fd,fd_temp;
int i;
size_t nread, size;
char filename[20]="\0";
char *buf=NULL;
if((fd=open(argv[1],O_RDONLY)) == -1)
{
perror("open:");
exit (1);
}
printf("input the size: ");
scanf("%d",&size);
buf=(char *)malloc(size);
while( (nread=read(fd, buf , size)) > 0)
{
memset(buf, 0, size);
sprintf(filename, "%s%d.txt", argv[1], i++);
if( (fd_temp=open(filename, O_CREAT, 0644)) == -1)
{
perror("open filename");
exit (2);
};
write(fd_temp, buf, nread);
close(fd_temp);
}
free(buf);
close(fd);
return 0;
}
阅读(881) | 评论(0) | 转发(0) |