红联Linux门户
Linux帮助

将键盘的输入写入文件中,请各位大侠帮我看看程序的问题在哪里

发布时间:2006-08-20 20:09:04来源:红联作者:scarface
程序目的:将键盘输入写入到文件中
问题情况:输入之后,回车,能够显示“we have got * char”,但是程序运行之后,1.txt中为空白,不知道是什么原因,我是新手,请各位多指教
#include
#include
#include
#include
#define BUFFSIZE 8192

int main()
{
char buf[BUFFSIZE];
int fd,n;
if((fd=open("1.txt",O_CREAT|O_EXCL,S_IRWXU))==-1)
{
printf("open file error!\n");
exit(1);
}
if((n=read(STDIN_FILENO,buf,BUFFSIZE))>0)
{
write(fd,buf,n);
printf("\nwe have got %d char\n",n);
}
close(fd);
exit(0);
}
文章评论

共有 0 条评论