免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1577 | 回复: 2
打印 上一主题 下一主题

[C] 【C新手的简单问题】 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-11 17:49 |只看该作者 |倒序浏览
这是我的代码:


  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 #include <string.h>
  5 #include <fcntl.h>
  6 #include <sys/stat.h>
  7 #include <sys/types.h>
  8
  9 #ifdef HAVE_MMAP
10 #include <sys/mman.h>
11 #endif
12
13 #include <sys/file.h>
14
15 int main (int argc, char ** argv)
16 {
17
18     int fd = open("x", O_RDWR);
19      char * c = malloc(10000);
20      memset(c, 0, 10000);
21
22     write (fd, c, 10000);
23     lseek(fd, 1000, SEEK_SET);
24     write (fd, "ccccccc", 10);
25     close(fd);
26     
27     printf("%s\n", *argv);
28 }
29



编译之后,跑一下,然后:

[occa]:/build/pgsql/cfile--> cat x
ccccccc%s[occa]:/build/pgsql/cfile-->

这个东西 %s  是怎么跑进来的呢?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2008-07-11 18:11 |只看该作者
你后面printf里面的%s,呵呵,你多write东西了。

论坛徽章:
0
3 [报告]
发表于 2008-07-11 18:25 |只看该作者
原帖由 aero 于 2008-7-11 18:11 发表
你后面printf里面的%s,呵呵,你多write东西了。



谢谢老大,明白了。


由此可以看出 cat 程序是用write 读入数据的,然后用printf之类的输出的。不知道这个结论对不对呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP