Linux程序设计考试例题.docxVIP

  • 3
  • 0
  • 约4.51千字
  • 约 6页
  • 2020-09-04 发布于天津
  • 举报
} } 例题 1 程序 A 生成 1 个文件,其大小为 1000 字节,其内容为小写字母 abcd...z 的循环。试 编写该程序。 文件名 t1.c #include stdio.h #include stdlib.h #include fcntl.h int main() { char x; int i; int fd=open(aa,O_CREAT|O_TRUNC|O_WRONLY,0666); if(fd0){printf(open !\r\n);exit(0);}; for(i=0;i1000;i++) { x=a+(i%26); write(fd,x,1); } close(fd); } 例题 2 读出一个文件 a.txt 的倒数第 2 个字节和倒数第 1 个字节,显示在屏幕上。并且显示 出当前时间。 文件名 t2.c #include stdio.h #include stdlib.h #include fcntl.h #include time.h int main() { char x[2]; int fd=open(a.txt,O_RDONLY); if(fd0){printf(open !\r\n);exit(0);}; lseek(fd,-3,SEEK_END); read(fd,x,2); printf( 倒数第二和第一字节为 %c %c\r\n,x[0]

文档评论(0)

1亿VIP精品文档

相关文档