Linux下C语言对文件读写的系统调用问题

santld 2002-02-20 03:40:34
源代码:

#include <unistd.h>
#include <stdlib.h>

int main()
{
char buffer[128];
int nread;

nread=read(0,buffer,128);
if(nread==-1){
write(2,"read error\n",11);
exit(1);
}
if((write(1,buffer,nread))!=nread)
write(2,"write error\n",12);
exit(0);
}

编译执行该文件:
$ echo this is a file | filename
总是无法进行正常输出,请问各位高手是何原因????
...全文
67 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
santld 2002-02-21
  • 打赏
  • 举报
回复
我编译怎么突然也正常了
wwwunix 2002-02-20
  • 打赏
  • 举报
回复
我编译执行很正常呀.

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧