#include <iohead.h>
int main(int argc, const char *argv[])
{
umask(0);
int p1=open("./5_rdon.c",O_RDONLY);
int p2=open("./cp_5",O_WRONLY|O_CREAT|O_TRUNC,0777);
if(EOF==p1||EOF==p2)
{
ERRLOG("open error");
}
char str[128]={0};
ssize_t ret;
while(1)
{
ret=read(p1,str,sizeof(str)-1);
if(ret==0)
{
printf("读取到结尾\n");
break;
}
else if(-1==ret)
{
ERRLOG("read error");
}
if(0==write(p2,str,sizeof(str)-1))
{
printf("write error\n");
return -1;
}
}
if(-1==close(p1))
{
ERRLOG("close error");
}
if(-1==close(p2))
{
ERRLOG("close error");
}
return 0;
}
#include <iohead.h>
int main(int argc, const char *argv[])
{
int p1=open("./1_cp.c",O_RDONLY);
if(p1==EOF)
{
ERRLOG("error open");
}
char str[128]={0};
int count=0;
ssize_t ret;
while(1)
{
if(0==(ret=read(p1,str,sizeof(str)-1)))
{
printf("end\n");
break;
}
else if(-1==ret)
{
ERRLOG("read error");
}
str[ret]='\0';
char *p=str;
while(*p)
{
if(*p=='\n')
count++;
p++;
}
}
printf("%d\n",count);
if(-1==close(p1))
{
ERRLOG("close");
}
return 0;
}

973

被折叠的 条评论
为什么被折叠?



