/*1.制作文件1.txt -- 10.txt
1.txt 1 2 3 4 5 6 7 8 9 10
2.txt 11 12 13 14 15 16 17 18 19 20
...
10.txt 91 92 93 94 95 96 97 98 99 100
sprintf(buf,"%d.txt",2);
*/
#include
#include
#include
#include
#include
#include
#include
int main()
{
char buf[100] = {};
int i = 0, j = 0;
char * p = NULL;
char * q = NULL;
int fd = -1;
for(i = 0; i < 10; i++)
{
sprintf(buf,"%d.txt",i+1);
fd = open(buf,O_RDWR|O_TRUNC|O_CREAT,0755);
if(fd < 0)
{
perror("open");
_exit(1);
}
lseek(fd,41-1,SEEK_SET);
write(fd, " ",1);
p = mmap(NULL,41,PROT_WRITE,MAP_SHARED,fd,0);
if(p == MAP_FAILED)
{
perror("mmap");
exit(1);
}
close(fd);
for(q = p,j = 1; j <= 10; j++)
{
sprintf(buf,"%03d ", i * 10 + j);
memcpy(q, buf, strlen(buf));
q += strlen(buf);
}
memcpy(q,"\n",1);
munmap(p,41);
}
return 0;
}
//------------------------我是分割线----------
/*1.制作文件1.txt -- 10.txt
1.txt 1 2 3 4 5 6 7 8 9 10
2.txt 11 12 13 14 15 16 17 18 19 20
...
10.txt 91 92 93 94 95 96 97 98 99 100
sprintf(buf,"%d.txt",2);
*/
#include
#include
#include
#include
#include
#include
#include
int main()
{
char buf[100] = {};
int i = 0, j = 0;
char * p = NULL;
char * q = NULL;
int fd = -1;
for(i = 0; i < 10; i++)
{
sprintf(buf,"%d.txt",i+1);
fd = open(buf,O_RDWR|O_TRUNC|O_CREAT,0755);
if(fd < 0)
{
perror("open");
_exit(1);
}
lseek(fd,41-1,SEEK_SET);
write(fd, " ",1);
p = mmap(NULL,41,PROT_WRITE,MAP_SHARED,fd,0);
if(p == MAP_FAILED)
{
perror("mmap");
exit(1);
}
close(fd);
for(q = p,j = 1; j <= 10; j++)
{
sprintf(buf,"%03d ", i * 10 + j);
memcpy(q, buf, strlen(buf));
q += strlen(buf);
}
memcpy(q,"\n",1);
munmap(p,41);
}
return 0;
}
//------------------------我是分割线----------
阅读(1174) | 评论(0) | 转发(0) |